![]() |
|
|
|
#1
|
|||
|
|||
|
I have a macro that triggers a Save As dialog box whenever a custom dotm file was 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.
Code:
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
|
|
#2
|
|||
|
|||
|
]I don't see why your SaveDoc macro is not executed when you open the template.
You can try putting a stop in the AutoOpen macro then when your code hits the step, stop through (with the F8 key) and troubleshoot. Maybe the CustomDocumentProperties.Count is not = 0 [CODE]Sub AutoOpen() Stop If ActiveDocument.CustomDocumentProperties.Count = 0 Then ActiveDocument.CustomDocumentProperties.Add Name:="AlreadyProcessed", LinkToContent:=False, Value:=1, Type:=msoPropertyTypeBoolean FormatCaptions CentreFigures SaveDoc Selection.HomeKey Unit:=wdStory End If End Sub[/CODE |
|
#3
|
|||
|
|||
|
Why are you saving a copy of your .dotm?
Why not simply start a new document based on it? Or, are you doing this so you have a backup? |
|
#4
|
|||
|
|||
|
Hi Greg, thanks for your response. I have added Stop but nothing changed.
|
|
#5
|
|||
|
|||
|
Hi Charles,
I am saving a copy of a .dotm file because I need to add some functionality to the macro-enabled template. When I add the new functionality, the .dotm file stops triggering the Save As dialog when the file is opened. To test what went wrong, I simply opened a working .dotm file, made a minor change to an existing comment line, and saved it. Even this stops the function where opening the .dotm file results in the Save As dialog. Regards, Aman |
|
#6
|
|||
|
|||
|
Hi Greg,
I think, as you said, maybe the CustomDocumentProperties.Count is not 0. Any input on how this can be fixed? regards, Aman |
|
#7
|
|||
|
|||
|
I think now I know what I was doing wrong.
Let me try it and if it will work, will update the solution here. |
|
#8
|
|||
|
|||
|
Just to clarify:
You are opening the template for editing, not using it to create a new document? You want a backup saved in addition to the one provided by the Save Backup function? Again, the customary use of a document template is the creation of new documents based on the template, not opening the template. Quote:
|
|
#9
|
|||
|
|||
|
If you added the Stop and then stepped through the code as I suggested, you will be all to tell if the .Count = 0 or not. If .Count is not = 0 then your code to save the document is not being called. What happens if you remove the If ... and the ... End If lines?
At least then the code to save will be called. |
|
#10
|
|||
|
|||
|
Thanks Greg! It worked.
Quote:
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| instance a new dotm file from a Word dotm file and save with new file name | David Peck | Word VBA | 3 | 08-18-2023 06:47 AM |
| Save a range of pages as PDF/New Word file with SaveAs Dialog box popup | smj.javid | Word VBA | 3 | 10-11-2021 04:11 AM |
save dialog box promt doesn't save file
|
brmveen | Word VBA | 2 | 11-04-2015 12:51 AM |
| Updating active R/O templates (dot) and macros (dotm) | gw1500se | Word | 0 | 05-27-2014 12:11 PM |
How to deactivate File Save dialog box
|
KIM SOLIS | Word | 3 | 12-15-2013 12:30 PM |