Saving new file in working directory

dl7631

Board Regular
Joined
Mar 6, 2009
Messages
114
Hi!

I created a macro. At the end of this macro I want to save my active workbook as a new file. Here is what I wrote:

ActiveWorkbook.SaveAs Filename:= _
"TV&Radio_" & Sheets("Template").Range("B7") & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False

Problem: It saves the file under "MyDocuments". However, I want it to be saved in the same directory that I am working in.

Advice?

Thanks a lot!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi!

I created a macro. At the end of this macro I want to save my active workbook as a new file. Here is what I wrote:

ActiveWorkbook.SaveAs Filename:= _
"TV&Radio_" & Sheets("Template").Range("B7") & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False

Problem: It saves the file under "MyDocuments". However, I want it to be saved in the same directory that I am working in.

Advice?

Thanks a lot!

activeworkbook.saveas ("S:\Your Folder\TV&Radio_" & sheets("Template").range("B7") & ".XLSX")
 
Upvote 0
activeworkbook.saveas ("S:\Your Folder\TV&Radio_" & sheets("Template").range("B7") & ".XLSX")

Sorry, I am afraid it won't work for me. I was not clear: am not creating this macro for myself. It will be for a bunch of other people. This macro should be saving the file in the working directory of the person using it - whatever this folder might be.
Makes sense?
Thank you again!
Dimitri
 
Upvote 0
Sorry, I am afraid it won't work for me. I was not clear: am not creating this macro for myself. It will be for a bunch of other people. This macro should be saving the file in the working directory of the person using it - whatever this folder might be.
Makes sense?
Thank you again!
Dimitri


are the folders being worked out of denoted anyway? like username for example.
 
Upvote 0
No. The file will be sent to different users. No information is available as to where their folders will be - some people might have it on their desktops, others - in their "MyDocuments", others - god knows where.
 
Upvote 0
No. The file will be sent to different users. No information is available as to where their folders will be - some people might have it on their desktops, others - in their "MyDocuments", others - god knows where.

if its being sent to them then wont it be cached in a temp file unless they manually save it somewhere themselves.
 
Upvote 0
They open the file, save it in the folder where they want to work (like anyone would do it) and then work with it. They open it, do something, hit the macro button and then the macro creates a new file that it has to save. The code I sent saves it under "My Documents". I would like it to be saved in the directory the person has the file with the macro open.
 
Upvote 0
try at the start of your code

dim sPath as string

sPath = activeworkbook.path

and then when you save your file

activeworkbook.saveas(sPath & "TV&RADIOblabla.xls")
 
Upvote 0
It's not really working.
I added to lines at the top of my code:

Dim sPath As String
sPath = ActiveWorkbook.Path

And my "save" code looked like this:

ActiveWorkbook.SaveAs (sPath & "TV&Radio_" & Sheets("Template").Range("B7") & ".xlsx")

2 problems with it:
1. It includes the name of the folder into the name of the file, which I'd like to avoid.
2. It saves it one level above the working directory (not sure why).

I would hope there is a straightfoward way of saying: save this file right here.
No?
 
Upvote 0
It's not really working.
I added to lines at the top of my code:

Dim sPath As String
sPath = ActiveWorkbook.Path

And my "save" code looked like this:

ActiveWorkbook.SaveAs (sPath & "TV&Radio_" & Sheets("Template").Range("B7") & ".xlsx")

2 problems with it:
1. It includes the name of the folder into the name of the file, which I'd like to avoid.
2. It saves it one level above the working directory (not sure why).

I would hope there is a straightfoward way of saying: save this file right here.
No?

no its not straight forward you want excel to somehow know where the person is saving a file which can only be done with the filepath property

you need a \ before your filename

if you print the path to a cell you can see that it doesnt put he last \ on

activework.saveas(spath & "\filename.xls")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

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