作者newacc (XD)
看板Office
標題Re: [問題] VBA dim使用問題
時間Fri Oct 13 11:22:17 2023
建議跨檔案、跨工作表,在使用物件時都要指定好父物件是誰
不然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
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.174.5.25 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Office/M.1697167339.A.D2F.html
1F:推 happyrun: 感謝提供另一種不同寫法!謝謝你~! 10/13 22:12