Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Save file to same directory folder

Hi,

I need to rename a file and save that file to the same folder where the
original is saved (via VBA code).

I find that if I've also opened another file from another folder, this
particular file I wish to save with a new name is saved to the wrong folder.
I don't want to set a folder as it could change from computer to computer.
I just want to make sure that wherever the original file is stored, the code
saves to the newly named file to that same folder.

I notice that when I manually select SaveAS, it opens to the correct folder,
but running the code below, the folder it saves to is unfortunately the one
last opened or saved to.

Sub SaveRollover()
'This saves the rolled over file with a new file name.

Dim WB As Workbook
Dim newFileName As String
Dim rng As Range
Set rng = Sheets("Setup").Range("P2")

On Error GoTo Oops

newFileName = rng.Text
Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
rng.Text _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=True
Etc....

Rob

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default Save file to same directory folder

Provide the file path and you will know where it is...

Filename:=ThisWorkbook.Path & Application.PathSeparator & rng.Text
--
Jim Cone
Portland, Oregon USA
easy ways to sort... http://www.contextures.com/excel-sort-addin.html



"RobN"
wrote in message
...
Hi,
I need to rename a file and save that file to the same folder where the
original is saved (via VBA code).

I find that if I've also opened another file from another folder, this
particular file I wish to save with a new name is saved to the wrong folder.
I don't want to set a folder as it could change from computer to computer.
I just want to make sure that wherever the original file is stored, the code
saves to the newly named file to that same folder.

I notice that when I manually select SaveAS, it opens to the correct folder,
but running the code below, the folder it saves to is unfortunately the one
last opened or saved to.

Sub SaveRollover()
'This saves the rolled over file with a new file name.
Dim WB As Workbook
Dim newFileName As String
Dim rng As Range
Set rng = Sheets("Setup").Range("P2")

On Error GoTo Oops
newFileName = rng.Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
rng.Text _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=True
Etc....
Rob

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Save file to same directory folder

Thanks Jim. Worked first time. A logical and easy solution!

Rob

"Jim Cone" wrote in message
...
Provide the file path and you will know where it is...

Filename:=ThisWorkbook.Path & Application.PathSeparator & rng.Text
--
Jim Cone
Portland, Oregon USA
easy ways to sort... http://www.contextures.com/excel-sort-addin.html



"RobN"
wrote in message
...
Hi,
I need to rename a file and save that file to the same folder where the
original is saved (via VBA code).

I find that if I've also opened another file from another folder, this
particular file I wish to save with a new name is saved to the wrong
folder.
I don't want to set a folder as it could change from computer to computer.
I just want to make sure that wherever the original file is stored, the
code
saves to the newly named file to that same folder.

I notice that when I manually select SaveAS, it opens to the correct
folder,
but running the code below, the folder it saves to is unfortunately the
one
last opened or saved to.

Sub SaveRollover()
'This saves the rolled over file with a new file name.
Dim WB As Workbook
Dim newFileName As String
Dim rng As Range
Set rng = Sheets("Setup").Range("P2")

On Error GoTo Oops
newFileName = rng.Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
rng.Text _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=True
Etc....
Rob

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
in which folder can you save a .CSV file? chivagirl Excel Discussion (Misc queries) 17 December 31st 07 10:44 PM
file save error: the file or directory cannot be created dublg Excel Discussion (Misc queries) 1 September 25th 06 07:07 PM
Automatically save a file in another directory MarkT Excel Discussion (Misc queries) 4 September 18th 06 02:53 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
How do I save a read only file or folder? Dick Excel Discussion (Misc queries) 3 March 4th 05 03:29 AM


All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"