Run-Time error 438 - Object doesn't support this property or method

ConorMoran1

New Member
Joined
Jan 11, 2017
Messages
2
Hi Everyone

I am very new to VBA to please go easy...

I am at the tail end of a project where I need a command button to copy data from another workbook into my workbook based on a filepath that can be entered in cell D4.

The reason I cannot put the filepath name in the VBA code is due to the fact the files name will change depending on the date.

I have come up with this VBA however I am getting an an error saying "Run-Time error 438 - Object doesn't support this property or method".

Can anyone shed any light as to where I am going wrong?

Thanks in advance.




Sub CommandButton21_Click()
Dim filepath As String
Dim x As Workbook 4
Dim Y As Workbook
filepath = ActiveSheet.Active("D4").Value
Set x = Workbooks.Open(filepath)
Set Y = Workbooks.Open("S:\ICC.Restored.20140103\# IBC #\New Build Team")
x.Sheets("Page1_1").Range("A6:U21000").Copy
Y.Sheets("Monday").Range("A2903").PasteSpecial
'close x:
x.Close
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Just an update I have worked out the issues however I am now getting a read only error from this. Does anyone have any idea how to get around this?

I am getting an error saying "excel cannot access 'myfolder' document may be read only or encrypted".

Code is below

Sub CommandButton21_Click()

Dim x As Workbook
Dim Y As Workbook
Dim Fpath As String
Fpath = Range("D4")
Set x = Workbooks.Open(Fpath, ReadOnly:=True)
Set Y = Workbooks.Open("S:\ICC.Restored.20140103\# IBC #\New Build Team")
x.Sheets("Page1_1").Range("A6:U21000").Copy
Y.Sheets("Monday").Range("A2903").PasteSpecial
'close x:
x.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,459
Messages
6,130,758
Members
449,588
Latest member
accountant606

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top