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
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