Save as, to save to the same folder with vba?

Lil2606

Board Regular
Joined
Jan 29, 2019
Messages
79
Hi all,

I have the following code, but this saves my workbook to C:/Documents.. is there a way to make it save to the same folder, my original file is in?

I have this Workbook full of macros and code which allows data manipulation efficiently sort of a 'Raw data converter', and this last macro would create the 'final formatted Data' version, saved as an xlsx, so it can be just stored, but the original 'converter' file will be on a shared drive, so I am not sure whre this macro will save to, if its not specified..

Could someone help me with this please?

Code:
Sub Finalize()

Worksheets(Array("Info&Admin", "Data Summary")).Copy


ActiveWorkbook.SaveAs Filename:="Data_export " & Format(Date, "DD-MM-YYYY"), FileFormat:=xlWorkbookDefault


ActiveWorkbook.Close


End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try
Code:
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\Data_export " & Format(Date, "DD-MM-YYYY"), FileFormat:=xlWorkbookDefault
 
Upvote 0
Maybe something like this:

Code:
Sub Finalize()

[COLOR=#ff0000]Dim pth as String

pth = Activeworkbook.Path[/COLOR]

Worksheets(Array("Info&Admin", "Data Summary")).Copy

ActiveWorkbook.SaveAs Filename:= [COLOR=#ff0000]pth[/COLOR] [COLOR=#ff0000]&[/COLOR] "[COLOR=#ff0000]\[/COLOR]Data_export " & Format(Date, "DD-MM-YYYY") [COLOR=#ff0000]& ".xlsx"[/COLOR], FileFormat:=xlWorkbookDefault

ActiveWorkbook.Close

End Sub
 
Upvote 0
You are welcome. Glad we were able to help.
Yep, people often forget the last back slash.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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