PDA

View Full Version : [SOLVED:] please help! Word VBA save as dialog



AspiredWrite
09-12-2016, 01:05 AM
I've scoured the internet and can't find a solution that works despite this being an elemental thing to do.

when I create a SaveAs dialog in Word VBA it doesn't save the file, that needs to be done seperately. But to where? All I've managed is to get the file name to save but not the path and if the user decides to change the location inside the Save As dialog, how do I get the path to save to?

I've tried



dim adress as string
adress = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)


as suggested here and there but I get a runtime error (5): "Invalid procedure call or argument"
this is my code:


Sub ShowSaveAsDialog()
Dim a As String
a = "cancelled"
With Dialogs(wdDialogFileSaveAs)
If .Display <> 0 Then
a = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1) 'this throws the above error
' a = .name 'alternate. this gives just the filename without the full path
End If
End With
msgbox a
End Sub


This must be simple right? Help please!

mana
09-12-2016, 05:26 AM
Sub test()
Dim myPath As String
myPath = CreateObject("Wscript.Shell").SpecialFolders("Desktop") & "\"

With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = myPath
If .Show Then MsgBox .SelectedItems(1)
End With

End Sub

Paul_Hossler
09-12-2016, 05:53 AM
Option Explicit

'http://software-solutions-online.com/vba-save-file-dialog-filedialogmsofiledialogsaveas/

Sub ShowSaveAsDialog()
Dim intChoice As Long
Dim strPath As String

'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogSaveAs).Show

'determine what choice the user made
If intChoice <> 0 Then
'get the file path selected by the user
strPath = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)
'displays the result in a message box
Call MsgBox(strPath, vbInformation, "Save Path")
End If

End Sub

AspiredWrite
09-12-2016, 05:59 AM
Sub test()
Dim myPath As String
myPath = CreateObject("Wscript.Shell").SpecialFolders("Desktop") & "\"

With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = myPath
If .Show Then MsgBox .SelectedItems(1)
End With

End Sub


This opens a whole new dialog that only lets the user select a path but does not let the user choose a filename and extension. if I were to combine this with the SaveAs dialog (where it allows for browsing) it would confuse the user. I suppose I could make my own form to get the filename if need be. Is there no way to get the path directly from the SaveAs dialog?

Thanks for your response

AspiredWrite
09-12-2016, 07:36 AM
Thank you so much! This works beautifully! Now I can finish my program (it was the only thing missing) :yes

Kilroy
10-25-2016, 07:28 AM
.