I have written some code that copies data from one workbook to another - using share point as file path. It works on all machines expect on one computer, the user is getting a Run-time error '9' (see below). I assume it cant be a file path issue as it works on others machines. I Thought perhaps if I changed the code around but does same thing that it would work - but it didn't...You can see the code I tried as it is commented out. Could it be a setting on the user machines/excel doc. Or is there other code I should try?
Thanks for all help
Private Sub CommandButton1_Click()
Dim x As Workbook
Dim y As Workbook
'Dim ws1 As Worksheet, ws2 As Worksheet'
Set x = Workbooks.Open("filepath.xlsx")
Set y = Workbooks.Open("filepath.xlsm")
'y.Sheets("Data").Range("A2") = x.Sheets("Form1").Range("C2:I1000")
x.Sheets("Form1").Range("C2:I1000").Copy
y.Sheets("Data").Range("A2").PasteSpecial
x.Close
'Set ws1 = x.Sheets("Form1")
'Set ws2 = y.Sheets("Data")
'ws1.Range("C2:I1000").Copy: ws2.Range("A2").PasteSpecial xlPasteValues
'x.Close True
'y.Close False
Call dropdown
End Sub
It has a problem with this line of code (debug):
y.Sheets("Data").Range("A2").PasteSpecial
Error message:
Run-time error '9':
Subscript out of range