![]() |
|
|
|
#1
|
|||
|
|||
|
Cannot seem to set the path for Word 2016 SaveAs screen. The statement
Code:
MsgBox Options.DefaultFilePath(wdDocumentsPath) But, after executing Code:
'source: based on https://wordmvp.com/FAQs/MacrosVBA/SetDefFilename.htm
'change properties
Dim dtToday As Date
dtToday = Date
If Documents.Count > 0 Then
Set dlgProp = Dialogs(wdDialogFileSummaryInfo)
' Establish title
dlgProp.Title = "Waiver_" & dtToday & ".docx"
' Set the values
dlgProp.Execute
' Show the dialog for testing purposes
dlgProp.Show
End If
And with the bogus message Quote:
The keywords I use in this forum's search bring up how to change file names, but not directories. I guess this ability qualifies merely as a "nice to have". But it really would be a nice-to-have. |
|
#2
|
||||
|
||||
|
Your code simply sets a document property. It does not set the file path. To change the path, use
Code:
ChDir "path" Code:
Dim dtToday As String
Dim sPath As String
sPath = Options.DefaultFilePath(wdDocumentsPath) & "\"
dtToday = Format(Date, "ddmmyyyy")
MsgBox sPath & "Waiver_" & dtToday & ".docx"
ActiveDocument.SaveAs2 sPath & "Waiver_" & dtToday & ".docx"
Code:
Dim dtToday As Date dtToday = Date
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thank you @gmayor
Please confirm that I modified your example correctly. Specifically I added Code:
Options.DefaultFilePath(wdDocumentsPath) = "C:\Users\Brian\Documents" Code:
Private Sub CommandButton3_Click()
Dim dtToday As String
Dim sPath As String
Options.DefaultFilePath(wdDocumentsPath) = "C:\Users\Brian\Documents"
sPath = Options.DefaultFilePath(wdDocumentsPath) & "\"
dtToday = Format(Date, "ddmmyyyy")
MsgBox sPath & "Waiver_" & dtToday & ".docx"
ActiveDocument.SaveAs2 sPath & "Waiver_" & dtToday & ".docx"
End Sub
|
|
#4
|
||||
|
||||
|
There is no need to change the path. Simply tell the macro where to save the document. The following will save the file in the appropriate place regardless of the current save location.
Code:
Private Sub CommandButton3_Click()
Dim dtToday As String
Dim sPath As String
sPath = Options.DefaultFilePath(wdDocumentsPath) & "\"
dtToday = Format(Date, "ddmmyyyy")
ActiveDocument.SaveAs2 sPath & "Waiver_" & dtToday & ".docx"
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#5
|
|||
|
|||
|
@gmayor wrote
Quote:
Code:
MsgBox Options.DefaultFilePath(wdDocumentsPath) & "\" Quote:
Does that not require resetting the the path through Options.Default(wdDocumentsPath)? Last edited by grNadpa; 04-03-2022 at 06:41 AM. Reason: typos |
|
| Tags |
| path, save as docx, vba code |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Temporary work file | reglilly | Word | 4 | 05-15-2018 12:13 PM |
| How to delete a temporary ~$ Word file? | Belloc | Word | 3 | 08-16-2017 06:24 AM |
Change word temporary location
|
mkhorrami | Word | 1 | 01-11-2016 04:09 AM |
| Where does Word 2010 save temporary files? | JonahSnow | Word | 1 | 06-03-2015 12:31 AM |
VBS saveas API behaviour is different from Menu saveas
|
Ahmed AbuZekry | Word VBA | 2 | 03-23-2015 02:14 AM |