PDA

View Full Version : Triggering Save As dialog box when updating a dotm file



amankap
05-14-2024, 06:36 PM
I have a macro that trigger a Save As dialog box whenever a custom dotm file is opened. I made a minor change to the macro, but now the Save As dialog box is not triggered when I open the dotm file. Can anyone provide guidance on what I might be missing? Thank you.


Sub AutoOpen()
If ActiveDocument.CustomDocumentProperties.Count = 0 Then
ActiveDocument.CustomDocumentProperties.Add Name:="AlreadyProcessed", LinkToContent:=False, Value:=1, Type:=msoPropertyTypeBoolean
Call FormatCaptions
Call CentreFigures
Call SaveDoc
Selection.HomeKey Unit:=wdStory
End If
End Sub

Private Sub FormatCaptions()

...
Private Sub CentreFigures()
...

Private Sub SaveDoc()
If ActiveDocument.Bookmarks.Exists("Title") Then
ActiveDocument.BuiltInDocumentProperties("Title") = ActiveDocument.Bookmarks("Title").Range.Text
Else
ActiveDocument.BuiltInDocumentProperties("Title") = ActiveDocument.Name
End If
ActiveDocument.BuiltInDocumentProperties("Company") = "XYZ"
ActiveDocument.BuiltInDocumentProperties("Author") = "ABC"
ActiveDocument.BuiltInDocumentProperties("Last author") = "LMN"
ActiveDocument.BuiltInDocumentProperties("Subject") = ""
ActiveDocument.BuiltInDocumentProperties("Keywords") = ""
ActiveDocument.BuiltInDocumentProperties("Category") = ""

With Dialogs(wdDialogFileSaveAs)
.Name = ActiveDocument.BuiltInDocumentProperties("Title")
.Format = wdFormatXMLDocument ' actually saves file as a DOCX
If .Show Then
.Execute
End If
End With

End Sub

DocAElstein
05-20-2024, 01:44 PM
Hello amankap
Welcome to ExcelFox

We don’t currently have many WORD experts passing here.
If you are still looking for help, here is one Word Sub forum that I know has some clever Word people passing by recently, https://eileenslounge.com/viewforum.php?f=26

I will take a guess that if you post this question there, then they would likely ask you the obvious question of what the minor change was that you made

Alan

kirin999
08-20-2024, 12:19 AM
The issue is that ActiveDocument refers to the dotm file itself, not the document being opened. Try changing ActiveDocument to ThisDocument in your SaveDoc sub.