question

JimmieTraylor-1527 avatar image
0 Votes"
JimmieTraylor-1527 asked MichaelHan-MSFT answered

Word 365-SP Content Type Document Template and BeforeSave Event_Issue 1 Macrobutton on New Document 2. BeforeSave on New Document

I have a Word Doc linked to a SharePoint Content Type to use on 100's of Document Libraries. I set up the Document Template for this Content Type to have 3 MacroButtons. One of the MacroButtons is linked to a Save Document Macro that automatically names the file based on fields in the document which works fine when testing from the original document in the document library it is stored in. I can enter date into the fields, press the button and a new file gets saved in a new document library on a site related to one of the field values.

Issue 1
When I open a document for this Content Type in any of the Document Libraries, the MacroButtons do not work. I have them set to work with 1 click (the double click feature is one of the worst ideas) but neither a single click or a double click seems to trigger the Macros. One of the reasons we have the Save Button is to make sure file names are standardized and the Save As UI has changed and no longer gives the current document library as the save to destination by default (users are constantly having trouble finding the correct document library to save in). How can I get the MacroButtons to trigger the Macros assigned on the New Document.?

Issue 2.
When the New Document is opened from the Document Library and someone hits the Word Default Save Button, the BeforeSave Event does not activate. I have Code in the BeforeSave Event to check if the Button was pressed (when the button is pressed i update a document property and check in the BeforeSave Code for that updated value) and if it was not then a Message Box tells them they have to use the button. On the New Document it automatically brings up the Save As UI as if the Before Save is not recognized. Again this works correctly from the Original Document.

I think the issues are related in that none of the VBA seems to be recognized on the New Document even though they are in the Document. I actually have about 9 different documents that need to work the same way so if anyone has any idea how i can fix these issues it would solve a lot of problems. I can provide a sample document if someone needs it.

office-sharepoint-online
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Save Document Code - (I am setting my document property and then invoking the beforesave by trying to save).


 Sub SaveDoct()
 'Set the tags field to say Save Proposal - Field Check for Saving
     For Each Prop In ActiveDocument.BuiltInDocumentProperties
         If Prop.Name = "Keywords" Then
             Prop.Value = "Save"
         End If
     Next Prop
 'This will call the save trap and run the code in the Class1 Module
     Activeocument.Save
    
 'Sets the tags field back to the doc control number after saving.
     For Each Prop In ActiveDocument.BuiltInDocumentProperties
         If Prop.Name = "Keywords" Then
             Prop.Value = "[DocControlNumber]"
         End If
     Next Prop
    
 End Sub

0 Votes 0 ·

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered

Hi @JimmieTraylor-1527,

Paul's answer in this post would be helpul to you: https://social.technet.microsoft.com/Forums/en-US/5b5a08ee-eb48-4187-8874-484f8ad5e614/macros-in-a-sharepoint-content-type-document-template-do-not-execute?forum=sharepointgeneralprevious

SharePoint Document templates aren't the same as Word templates. All Office templates are required to be stored on the local computer or a network drive mapped by the local computer. Although you can use a .dotx or .dotm as a SharePoint template. when you create a new document from a SharePoint Library it just makes a copy of the file and renames it as a document1.docx. The actual Office template used will revert to the template behind the .dot in SharePoint, normally the normal.dot in Word. As a result the macros aren't actually wired up in the file anymore since they were wired up by the template.


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.