下面是我到目前为止所尝试过的,尽管它立即错误地显示“Set wb1 = Workbooks("C:\Quotes\Quote List.xlsx")”。
(路径和电子表格名称/类型正确。)。我使用的是 Office 2019 中的 Excel。
Sub Workbook_Open()
Dim wb1 As Workbook 'Quote List
Dim wb2 As Workbook 'My Quote
Dim ws1 As Worksheet 'Quotes
Dim ws2 As Worksheet 'Quote
Set wb1 = Workbooks("C:\Quotes\Quote List.xlsx")
Set ws1 = wb1.Sheets("Quotes")
Set wb2 = ActiveWorkbook
SourcePath = "C:\Quotes"
Set ws2 = wb2.Sheets("Quote")
lastrow = ws1.Cells(ws.Rows.Count, "A").End(xlUp).Row
ws2.Range("I1").Value = ws1.Range(lastrow).Value + 1
End Sub
感谢您的帮助。
Sub Workbook_Open()
Dim wb1 As Workbook 'Quote List
Dim wb2 As Workbook 'My Quote
Dim ws1 As Worksheet 'Quotes
Dim ws2 As Worksheet 'Quote
Set wb2 = ThisWorkbook
Set wb1 = Workbooks.Open("C:\Quotes\Quote List.xlsx")
Set ws1 = wb1.Sheets("Quotes")
' SourcePath = "C:\Quotes"
Set ws2 = wb2.Sheets("Quote")
ws2.Range("I1").Value = ws1.Cells(ws.Rows.Count, "A").End(xlUp).Value + 1
End Sub