rhombus4
Well-known Member
- Joined
- May 26, 2010
- Messages
- 586
- Office Version
- 365
- 2016
- Platform
- Windows
Usually use code in TestCopy but then recently saw testCopy, so was wondering which is the best way
Also in the first version if it contains a password you can use that in the code but wasn't sure how to use in the Get Object version
and
Also in the first version if it contains a password you can use that in the code but wasn't sure how to use in the Get Object version
VBA Code:
Sub testCopy()
Dim wb As Workbook
Application.DisplayAlerts = False
Set wb = Workbooks.Open("C:\MyDocs\Test.xls", Password:="myPassword", ReadOnly:=True)
wb.Sheets("Sheet2").Range("A2:F100").Copy
ThisWorkbook.Sheets("Sheet1").Range("A2").PasteSpecial xlAll
wb.Close False
Application.DisplayAlerts = True
End Sub
and
VBA Code:
Sub testCopy2()
With GetObject("C:\MyDocs\Test.xls")
.Sheets("Sheet2").Range("A2:F100").Copy ThisWorkbook.Sheets("Sheet1").Range("A2")
.Close 0
End With
End Sub