Default File Path in a Macro

ebrandt

Board Regular
Joined
Dec 13, 2010
Messages
54
I have written a macro that copies worksheets from a workbook to a new workbook and saves it.

I want the new workbook to save to the same network file folder as the original.

It seems like everytime i run the macro it saves in a different location. Sometimes in the correct location. Often saves it to My Documents on my hard drive.

How do I write the macro to identify the file path of the current document and then save the new workbook to the same location?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Dim MyCurrPath As String
MyCurrPath = ThisWorkbook.Path
'Your Code to Copy to New Wb
 
Upvote 0
Thanks Jim,

That looks like the answer. I figured it was something simple. I will give this a try.
 
Upvote 0
Here's another go at it..

Sub Foo()
Dim MyDir As String
MyDir = CurDir

'your code here

End Sub
 
Upvote 0
Macro stopped on this statement;

ActiveWorkbook.SaveAs Filename:= _
MyCurrPath \ "Sub Analysis Sheet - " & Estimator & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

I assume I wrote this incorrectly??
 
Upvote 0
Try..

ActiveWorkbook.SaveAs Filename:= _
MyCurrPath & "\" & "Sub Analysis Sheet - Estimator" & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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