Results 1 to 10 of 10
  1. #1
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Saving file opened with custom template

    the below code is supposed to open a file based on a template I created and save it s .docx:
    Code:
    Documents.Add Template:=myPath & "\PFTtemplate.dotx"
     ActiveDocument.SaveAs2 FileName:=WorkDir & zFileName & ".docx"
    When the SaveAs is executing, a popup bos is asking: "Do you want to save changes to the document template?"
    Well, I don't. I want also to avoid this question.

    Did I miss a certain flag?

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    YigalB,

    Place this before your code: Application.DisplayAlerts = wdAlertsNone

    Place this after your code: Application.DisplayAlerts = wdAlertsAll

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by RetiredGeek View Post
    YigalB,

    Place this before your code: Application.DisplayAlerts = wdAlertsNone

    Place this after your code: Application.DisplayAlerts = wdAlertsAll

    HTH
    Thanks. It solved the problem of the message, but it modified also the template, so I guess it used the "Yes" as default.
    How can I change that?
    The template should remain untouched.

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    YigalB,

    Check out this MS Article scroll down to the 2007 (which applies to 2010 also). HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by RetiredGeek View Post
    YigalB,

    Check out this MS Article scroll down to the 2007 (which applies to 2010 also). HTH
    Hi

    The approach in that article may prevent the problem on my computer, but I can't control other computers where this form will be used.
    I was sure that templates are read-only if I open a word document based on that template.
    Is there a way to tell word "just use the template when starting up and forget about it afterwards"?
    Or perhaps I will copy the template to a temp template file, use this for loading, and delete it afterwards?


    Yigal

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Yigal,

    I found this try it before your save command:
    NormalTemplate.Saved = True
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by RetiredGeek View Post
    Yigal,

    I found this try it before your save command:
    NormalTemplate.Saved = True
    HTH
    I didn't work. I traced the code and found the exact line were the time of the template is modified: the SaveAs line.
    Code:
       Application.DisplayAlerts = wdAlertsNone
        NormalTemplate.Saved = True  ' hopefully this will cause template not to be touched
        ActiveDocument.SaveAs2 FileName:=WorkDir & zFileName & ".docx", AddToRecentFiles:=False
        Application.DisplayAlerts = wdAlertsAll

  8. #8
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Perhaps the source of the problem is with the save line.
    I used this code to create the file:
    Code:
    Documents.Add Template:=myPath & "\PFTtemplate.dotx"
    And I used this one to save:
    Code:
    ActiveDocument.SaveAs2 FileName:=WorkDir & zFileName & ".docx", AddToRecentFiles:=False
    Is there any mismatch or other error with these lines?

  9. #9
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I think I solved the problem. I am not 100% sure about the root cause, but I assumed that my "SaveAs" line did not convince word that the new format is docx, although the extension was docx.
    Reminder: this was the line I used to open the file:
    Code:
    Documents.Add Template:=myPath & "\PFTtemplate.dotx"
    and the line for saving the file:
    Code:
    ActiveDocument.SaveAs2 FileName:=WorkDir & zFileName & ".docx", AddToRecentFiles:=False
    I think that Word didn't use the SaveAs with the docx extension as a hint for the file format, maintaining it as template.

    After browsing many examples on the web, I decided to simulate the activity with macro record, and here is what I got for file open:
    Code:
    Documents.Open FileName:="PFTtemplate.dotx", ConfirmConversions:=False, _
            ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
            PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
            WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:="", _
            DocumentDirection:=wdLeftToRight
    And for the SaveAs:
    Code:
    ActiveDocument.SaveAs2 FileName:="PFTtemplate.docx", FileFormat:= _
            wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
            :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
            :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
            SaveAsAOCELetter:=False, CompatibilityMode:=14

    Now the file is considered docx, and no save requests are required.
    I also don't need the Application.DisplayAlerts to bypass the problem.

    Thank you HTH for helping me.

  10. #10
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Yigal,

    Glad you got it sorted!

    BTW: HTH = Hope This Helps.

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •