Hi, I have a macro that brings up a dialog box asking the user what they would like to name the file:
I have previously directed things to a specific folder like this:Dim MyInput MyInput = InputBox("What would you like to name the file? i.e. BT Report 10_12_11") Dim FN As String FN = MyInput ActiveWorkbook.SaveAs Filename:=FN & ".xls"
What I want to do now is have a second input box for the user to select the folder at the end of a specific path. What I tried was:Dim FP As String, FN As String FP = "W:\Planning\" FN = MyInput ActiveWorkbook.SaveAs Filename:=FP & FN & ".xls"
I have it wrong somewhere but I can't figure out where. Can anyone suggest a way of doing this? (the folders will always be in W:\Planning)Dim MyInput MyInput = InputBox("What would you like to name the file? i.e. BT Report 10_12_11") Dim MyInput2 MyInput2 = InputBox("Which folder would you like to save to?") Dim FP As String, FN As String FP = "W:\Planning\" & MyInput2 FN = MyInput ActiveWorkbook.SaveAs Filename:=FP & FN & ".xls"
Thanks,
Dean
Last edited by Dean81; 12-21-2011 at 05:33 AM.
you could do something like this
Dim FileSaveDLG As FileDialog Set FileSaveDLG = Application.FileDialog(msoFileDialogSaveAs) With FileSaveDLG If .Show = -1 Then ActiveWorkbook.SaveAs .SelectedItems(1) End If End With
That's the kitty! the only thing is it brings up My Documents as the default location, how can I make it open at say "W:\Planning", I tried adding ChDir at the start and after the "Then" but no joy. Any ideas?
Thanks for your response by the way. I don't know where I'd be without this forum!
add the line in bold
Dim FileSaveDLG As FileDialog Set FileSaveDLG = Application.FileDialog(msoFileDialogSaveAs) With FileSaveDLG .InitialFileName = "W:\Planning" If .Show = -1 Then ActiveWorkbook.SaveAs .SelectedItems(1) End If End With
Dean,
First, be sure to go back to your post #1 above and add CODE tags around your posted code, as per forum rules. We don't want your thread to get moderated, ok? Like mohd showed in their post above, and demonstrated in my signature below.
Once you have a "method" that seems to be getting you close, try a forum/Google search on the main keywords to see what other "parameters" might be available, or to just view other examples of the method. IN this case, the keyword search would be for FileDialog(msoFileDialogSaveAs)...
This is one of the additional parameters you can add:
Dim FileSaveDLG As FileDialog Set FileSaveDLG = Application.FileDialog(msoFileDialogSaveAs) With FileSaveDLG .InitialFileName = "W:\Planning\" If .Show = -1 Then ActiveWorkbook.SaveAs .SelectedItems(1) End If End With
You could even go further and have it fill in a suggested filename:
.InitialFileName = "W:\Planning\" & "MyFile-" & Format(Date, "mm-dd-yy")
Last edited by JBeaucaire; 12-21-2011 at 04:46 AM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Awesome! Thanks guys. That's exactly what I was after. Apologies for the lack of Code Tags.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks