VBA code - File Path Error

MEBAILEY

New Member
Joined
Nov 18, 2014
Messages
3
I am having a problem with VBA code related to the file path name. In Macro1 - the files are located on the C: drive with no folders and it works. In Macro2 - the files are in folders as shown in code below and does not work.

Please help - I need someone to show me the code to allow the file path to be work in Macro2. I am not sure if the spaces or "-" in the file path name are a problem.

Thanks, Marc B.


'Macro1 - working
Sub
Workbooks("LH - COA - Current.xlsm").Worksheets("COA - final").Range("B6:K200").Copy
Workbooks.Open("C:\COA.xlsm").Worksheets("CC-COA-Expense").Range("B6").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Workbooks("COA.xlsm").Close SaveChanges:=True
End Sub


'Macro2 - not working - file path error
Sub
Workbooks("LH - COA - Current.xlsm").Worksheets("COA - final").Range("B6:K200").Copy
Workbooks ("C:\Users\Marc\Desktop\In-Rhythm\- Life House\LifeHouse - Credit Card Master\LH - CC - Templates\2 LH-CC-Master\LH - CC - Angela Capito.xlsm")
Application.CutCopyMode = False
Workbooks("C:\Users\Marc\Desktop\In-Rhythm\- Life House\LifeHouse - Credit Card Master\LH - CC - Templates\2 LH-CC-Master\LH - CC - Angela Capito.xlsm").Close SaveChanges:=True
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You need to use the Opens method of the Workbooks collection. So in keeping with your first macro, try...

Code:
Workbooks.Open("C:\Users\Marc\Desktop\In-Rhythm\- Life House\LifeHouse - Credit Card Master\LH - CC - Templates\2 LH-CC-Master\LH - CC - Angela Capito.xlsm").Worksheets("CC-COA-Expense").Range("B6").PasteSpecial Paste:=xlPasteValues

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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