Saving a workbook to a specific directory

C

Chris Hankin

Hello,

Could someone please help amend my macro code so that when it is run,
the SaveAs window pops up and automatically selects the desired
directory location in my macro?

Sub Save_to_Dir()
'
'Save to Dir
'

Dim MyPath As String


Application.ScreenUpdating = False


MyPath = "G:\WLMAEWCSPO\LMU\LOGISTICS PREPAREDNESS SYSTEMS\LOGISTICS
SYSTEMS\LOGSYS3\LOCAL PURCHASE\ON-LINE DEMAND REQUESTS\"

MyPath = Application.GetSaveAsFilename


End Sub

Any help would be greatly appreciated.

Kind regards,

Chris.



*** Sent via Developersdex http://www.developersdex.com ***
 
V

Vergel Adriano

Change this line:

MyPath = Application.GetSaveAsFilename

to this:

MyPath = Application.GetSaveAsFilename(MyPath)
 
C

Chris Hankin

Thanks Vergel for your help.

I am still having difficulty saving my workbook to the desired directory
location. I changed the macro code to:

Sub Save_to_Dir()
'
'Save to Dir
'

Dim MyPath As String


Application.ScreenUpdating = False


MyPath = "G:\WLMAEWCSPO\LMU\LOGISTICS PREPAREDNESS SYSTEMS\LOGISTICS
SYSTEMS\LOGSYS3\LOCAL PURCHASE\ON-LINE DEMAND REQUESTS\"

MyPath = Application.GetSaveAsFilename("G:\WLMAEWCSPO\LMU\LOGISTICS
PREPAREDNESS SYSTEMS\LOGISTICS SYSTEMS\LOGSYS3\LOCAL PURCHASE\ON-LINE
DEMAND REQUESTS\AEWCSPO Online Demand Request")

End Sub

Could you please review the changed macro code and advise where I am
going wrong?

Kind regards,

Chris.


*** Sent via Developersdex http://www.developersdex.com ***
 
V

Vergel Adriano

Chris,

The call to GetSaveAsFilename will only display the "Save As" dialog and
allow you to get a filename from the user. It will not save the file.. To
do the save as, you can add these lines of code after the call to
GetSaveAsFilename

If MyPath <> "False" Then
ThisWorkbook.SaveAs MyPath
End If

Or, if you want to save the current active workbook, you can use

If MyPath <> "False" Then
ActiveWorkbook.SaveAs MyPath
End If
 
C

Chris Hankin

Thanks again Vergel,

I used the following code to fix my macro. It now works great.

If MyPath <> "False" Then
ActiveWorkbook.SaveAs MyPath
End If

Cheers,

Chris.



*** Sent via Developersdex http://www.developersdex.com ***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top