If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Macro Save As - Wrong Location

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-02-10, 16:19
debraanne16 debraanne16 is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
Macro Save As - Wrong Location

Hi

I'm using this macro to save a file with a title and today's date to a specific location.

Dim newFile As String, fName As String
fName = Range("B1").Value
newFile = fName & " " & Format$(Date, "mm-dd-yyyy")
ChDir _
"X:\Common\Service Centre\End of day reports\Current Report"
ActiveWorkbook.SaveAs Filename:=newFile

However on some occasions this macro is saving to My Documents rather than the file path shown above.

Can anyone help? Thanks
Reply With Quote
  #2 (permalink)  
Old 11-03-10, 05:40
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi,

Try including the path in the FileName argument.

Code:
Dim newFile As String, fName As String
 
fName = Range("B1").Value
newFile = fName & " " & Format$(Date, "mm-dd-yyyy")
 
ActiveWorkbook.SaveAs Filename:= _
    "X:\Common\Service Centre\End of day reports\Current Report" & newFile
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #3 (permalink)  
Old 11-03-10, 14:07
debraanne16 debraanne16 is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks, but the result is as follows:
- saving at X:\Common\Service Centre\End of day reports
- "Current Report" is now part of the file name
Reply With Quote
  #4 (permalink)  
Old 11-03-10, 16:42
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
My mistake, you need a \ after Current Report like this:
Code:
ActiveWorkbook.SaveAs Filename:= _
    "X:\Common\Service Centre\End of day reports\Current Report\" & newFile
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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