Re: [問題] VBA dim使用問題

作者: newacc (XD)   2023-10-13 11:22:17
建議跨檔案、跨工作表,在使用物件時都要指定好父物件是誰
不然excel預設是執行當下active的物件
Sub test()
Dim wb As Workbook, wb2 As Workbook, sh1 As Worksheet
Set wb = Workbooks("A")
Set sh1 = wb.Worksheets("C")
With sh1
Set wb2 = Workbooks.Open( _
Filename:=.Range("C36").Value & "\" & .Range("D36").Value)
wb2.Sheets("工作表3").Range("A:E").copy Destination:=.Range("A1")
End With
End Sub
作者: happyrun (小黃)   2023-10-13 22:12:00
感謝提供另一種不同寫法!謝謝你~!

Links booklink

Contact Us: admin [ a t ] ucptt.com