作者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/cn.aspx?n=bbs/Office/M.1697167339.A.D2F.html
1F:推 happyrun: 感谢提供另一种不同写法!谢谢你~! 10/13 22:12