Dynamically set SaveAs folder in VBA

X

XP

I have a program in which the user is prompted to save a file at a certain
point.

What I would like to do is, when the code reaches the file save prompt
(which I can already do), have VBA quietly set MS-Excel to point to the
desired folder, so that if the user clicks [File] then [Save] the SaveAs
dialog box is pointed at the target folder, that's all.

Please note, that this should only occur if the code reaches this point and
I don't want this folder to be set as the default folder or anything like
that...

Thanks in advance for your assistance.
 
R

Ron de Bruin

Use GetSaveAsFilename

This is the start filder
MyPath = "C:\Users\Ron\test\"

Below is a basic example

Sub test()
Dim FName As Variant
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = "C:\Users\Ron\test\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetSaveAsFilename("yourfilename", filefilter:="Excel Files (*.xls), *.xls")
If FName <> False Then
ActiveWorkbook.SaveCopyAs FName
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub
 
X

XP

Thanks Ron; I forgot about that!



Ron de Bruin said:
Use GetSaveAsFilename

This is the start filder
MyPath = "C:\Users\Ron\test\"

Below is a basic example

Sub test()
Dim FName As Variant
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = "C:\Users\Ron\test\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetSaveAsFilename("yourfilename", filefilter:="Excel Files (*.xls), *.xls")
If FName <> False Then
ActiveWorkbook.SaveCopyAs FName
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub





--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


XP said:
I have a program in which the user is prompted to save a file at a certain
point.

What I would like to do is, when the code reaches the file save prompt
(which I can already do), have VBA quietly set MS-Excel to point to the
desired folder, so that if the user clicks [File] then [Save] the SaveAs
dialog box is pointed at the target folder, that's all.

Please note, that this should only occur if the code reaches this point and
I don't want this folder to be set as the default folder or anything like
that...

Thanks in advance for your assistance.
 

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

Similar Threads

SaveAs? 4
Saveas Not Working 7
Loop and SaveAs Question 7
SaveAs dialog argument for file type 1
Prompt saveas location in Word from Excel 2
xlsm SaveAs xls 4
SaveAs 2
Confirm SaveAs takes place. 6

Top