It says Subscript is out of range. The workbook is already open. I have tried with a path ex:Set wkb2 = Workbooks("d:/A.xlms"). Also I have tried this Set wkb2 = Workbooks.open("d:/A.xlms") with workbook not open. It all returns error mentioning that the file doesn't exist.
Sub CopySourceToTarget()
Dim wkb1 As Workbook
Dim sht1 As Worksheet
Dim wkb2 As Workbook
Dim sht2 As Worksheet
Application.ScreenUpdating = False
Workbooks("A.xlsm").Activate
Set wkb1 = ThisWorkbook
Set wkb2 = Workbooks("A.xlsm") ----THIS LINE RETURNS THE ERROR----
Set sht1 = wkb1.Sheets("Product codes")
Set sht2 = wkb2.Sheets("Product")
sht1.Range("A8:AZ65000").Copy
sht2.Range("A4").PasteSpecial xlPasteValues
Application.CutCopyMode = False
wkb2.Close True
Application.ScreenUpdating = True
End Sub
I also tried this code and it's not working
Sub CopySourceToTarget()
Dim Source As Range, Target As Range
Set Source = Workbooks("Local Codes Creation1.xlsm").Worksheets("Product Codes").Range("A8:AZ6500")
Set Target = Workbooks("A.xlsm").Worksheets("Products").Range("A4:AZ7500")
Source.Copy Destination:=Target
End Sub
xlms
->xlsm
? – BathshebaActiveWorkbook
instead. – braXSub listallbooks(): For Each wkb In Application.Workbooks: Debug.Print Chr$(34) & wkb.Name & Chr$(34): Next: Exit Sub
and then in the immediate window enterlistallbooks
and hit enter. You should get a list of all workbooks that module can 'see'. – CLR