Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2015, 12:36 PM
ptmuldoon ptmuldoon is offline SaveAs docm file from template Windows 7 64bit SaveAs docm file from template Office 2013
Advanced Beginner
SaveAs docm file from template
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default SaveAs docm file from template

I have word macro enabled template file that that users use to create a new document from.



Is there a way to have the file default to be saved as a docm file for just that template file when the initially save their new document? I still want all other files to be saved under a normal docx format.

I starting to search google, but thinking/guessing maybe something with a BeforeSave Event?
Reply With Quote
  #2  
Old 03-05-2015, 06:07 PM
gmaxey gmaxey is offline SaveAs docm file from template Windows 7 32bit SaveAs docm file from template Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Yes you should be able to use the BeforeSave event. See if this gets you started:

Code:
Option Explicit
Private WithEvents m_oThisApp As Application
Private Sub Class_Initialize()
  'Syncronize class with application.
  Set m_oThisApp = Word.Application
lbl_Exit:
  Exit Sub
End Sub
Private Sub m_oThisApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim oDialog As Dialog
  If ActiveDocument.AttachedTemplate = ThisDocument.AttachedTemplate Then
    Cancel = True
    Set oDialog = Dialogs(wdDialogFileSaveAs)
    With oDialog
      .Format = 13
      .Show
    End With
  End If
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-06-2015, 07:02 AM
ptmuldoon ptmuldoon is offline SaveAs docm file from template Windows 7 64bit SaveAs docm file from template Office 2013
Advanced Beginner
SaveAs docm file from template
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

I think the code you provide makes sense, but I couldn't seem to get it work last night. I think I need to place the beginning WithEvent in a Class Module, and the rest either in ThisDocument or normal module.

I need to get some real work here done this morning, but will give it a 2nd try again later today.

And all of this does belong in the word macro template dotm file correct?
Reply With Quote
  #4  
Old 03-06-2015, 07:58 AM
gmaxey gmaxey is offline SaveAs docm file from template Windows 7 32bit SaveAs docm file from template Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Put this code in a standard module of your template:

Code:
Option Explicit
Private m_ThisApp As clsThisApp
Sub AutoNew()
  InitiateAppClass
lbl_Exit:
  Exit Sub
End Sub
Sub AutoOpen()
  InitiateAppClass
lbl_Exit:
  Exit Sub
End Sub
Sub InitiateAppClass()
  Set m_ThisApp = New clsThisApp
End Sub
Put the previous code in a class module that you have named clsThisApp
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 03-06-2015, 08:35 AM
ptmuldoon ptmuldoon is offline SaveAs docm file from template Windows 7 64bit SaveAs docm file from template Office 2013
Advanced Beginner
SaveAs docm file from template
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

A HUGE Thanks for helping with that.

I'm going to now try and modify that same information to work with an Excel file. Similar situation. Saving a new excel file off an an excel macro template to default to xlsm vs xlsx.
Reply With Quote
  #6  
Old 03-06-2015, 01:28 PM
ptmuldoon ptmuldoon is offline SaveAs docm file from template Windows 7 64bit SaveAs docm file from template Office 2013
Advanced Beginner
SaveAs docm file from template
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

Think I hit a small snag?

I want the document to only force the saving as a .docm file on the initial save as. The orginal code seemed to want to force a SaveAs during each save of the document as..

So I modded the If Statement to check if the SaveAsUI is true, and that seems to work, but......

What is strange is that you edit the document, then attempt to close the file and chose not to save, vba throws an error; runtime error 4248.

It appears to happen only if the document is open by itself as Word attempts to close the application and gives the error. If there are other word files open, it does not give the error.

I think I just need to tweak the If Statement some

Code:
Private Sub m_ThisApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim oDialog As Dialog
  If SaveAsUI = True And ActiveDocument.AttachedTemplate = ThisDocument.AttachedTemplate Then
    Cancel = True
    Set oDialog = Dialogs(wdDialogFileSaveAs)
    With oDialog
      .Format = 13
      .Show
    End With
  End If
    
End Sub
Reply With Quote
  #7  
Old 03-06-2015, 02:05 PM
gmaxey gmaxey is offline SaveAs docm file from template Windows 7 32bit SaveAs docm file from template Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Try this. I also think the Cancel may have been in the wrong place:

Code:
Private Sub m_oThisApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim oDialog As Dialog
  If ActiveDocument.FullName = ThisDocument.FullName Then Exit Sub
  If ActiveDocument.Path <> vbNullString Then Exit Sub
  If ActiveDocument.AttachedTemplate = ThisDocument.AttachedTemplate Then
    Set oDialog = Dialogs(wdDialogFileSaveAs)
    With oDialog
      .Format = 13
      .Show
    End With
    'I had the cancel in the wrong place. Suppress the normal dialog.
    Cancel = True
  End If
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #8  
Old 03-09-2015, 05:38 PM
ptmuldoon ptmuldoon is offline SaveAs docm file from template Windows 7 64bit SaveAs docm file from template Office 2013
Advanced Beginner
SaveAs docm file from template
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

Greg,

Thanks again!! I just to trying out the new code, and things work as they should.

Problem solved!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
SaveAs docm file from template DOCM file not saving on Microsoft Word 2010 flutterby1 Word 4 10-08-2014 10:55 AM
Quick Parts entries in .docm template lost kjworduser Word 7 07-31-2013 02:19 PM
SaveAs docm file from template How to convert docm to dotm without opening the file Moz Word 1 12-20-2012 04:23 PM
Docm content dissapearing when I open the file? shabbaranks Word 2 07-18-2012 01:13 AM
SaveAs docm file from template A newbie question: a must to save macro word file as .docm? tinfanide Word VBA 6 12-06-2011 03:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft