Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2014, 06:16 AM
Catty Catty is offline Disabling Word's Save and SaveAs commands Windows 7 32bit Disabling Word's Save and SaveAs commands Office 2010 32bit
Advanced Beginner
Disabling Word's Save and SaveAs commands
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default Disabling Word's Save and SaveAs commands

Is it possible to run my macro via word's Save command. So basically when the user clicks on Save/SaveAs, my macro will be called.



How do I go about doing this?
Reply With Quote
  #2  
Old 03-07-2014, 01:13 PM
fumei fumei is offline Disabling Word's Save and SaveAs commands Windows 7 64bit Disabling Word's Save and SaveAs commands Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Yes. Just have your macro procedure have the name.
Code:
 
Sub FileSave()
MsgBox "Blah blah blah"
ActiveDocument.Save
End Sub
Now running Save would give a messagebox, then do a save of the active documnent.
Reply With Quote
  #3  
Old 03-07-2014, 11:00 PM
Charles Kenyon Charles Kenyon is offline Disabling Word's Save and SaveAs commands Windows 7 64bit Disabling Word's Save and SaveAs commands Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You probably want it for both FileSave and FileSaveAs.

Note, with some commands this gets tricky.
Intercepting events like Save and Print
Reply With Quote
  #4  
Old 03-08-2014, 05:19 PM
fumei fumei is offline Disabling Word's Save and SaveAs commands Windows 7 64bit Disabling Word's Save and SaveAs commands Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Indeed. I do not know what your macro is supposed to do, but make sure you think things out fully before you start overwriting standard commands.
Reply With Quote
  #5  
Old 03-11-2014, 04:45 AM
Catty Catty is offline Disabling Word's Save and SaveAs commands Windows 7 32bit Disabling Word's Save and SaveAs commands Office 2010 32bit
Advanced Beginner
Disabling Word's Save and SaveAs commands
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

Hi, Thanks for your response.

What I want to do is:

1. Fill in 3 fields (content controls) on the document i.e. Name, Date (DateTimePicker) and Subject.
2. When the user Selects/Clicks on Save/Save As, the dialog box needs to display and
i) All the content in the 3 fields needs to be combined and displayed in the "File Name" field of the dlgbox
ii) The dlgbox needs to open from a specified path.


Below is my code. But for some reason, one minute it works and the next it doesn't. Please have a look and let me know what I'm doing wrong.

Code:
Sub FileSave()
'
' FileSave Macro
' Saves the active document or template
'
Dim strName As String, strDate As String, strSubject As String
Dim strDocName As String
Dim dlgSaveAs As FileDialog
Dim ccCtrl As ContentControl

On Error GoTo errhandler:

Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)

With ActiveDocument
strName = .ContentControls("1017512746").Range.Text

strDate = .ContentControls("2985804456").Range.Text

strSubject = .ContentControls("821630576").Range.Text
End With

strDocName = strName & "_" & strDate & "_" & strSubject

With dlgSaveAs

    If .Show = -1 Then
        .InitialFileName = "C:\" & strDocName
        .Title = strDocName

        ActiveDocument.SaveAs2 (strDocName)

    Else
    MsgBox ("Document not saved!")
    End If
        
End With

errhandler:
'MsgBox ("Error saving the document!")

End Sub
Reply With Quote
  #6  
Old 03-11-2014, 12:58 PM
Charles Kenyon Charles Kenyon is offline Disabling Word's Save and SaveAs commands Windows 7 64bit Disabling Word's Save and SaveAs commands Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Why
MsgBox ("Document not saved")
rather than
MsgBox "Document not saved"
?

You are certainly going to get an error if one or more of your content controls does not exist.

I do not know what you mean by "the dlgbox needs no open from a specific path." Have the path for saving be a specific path?

The string concatenation looks fine.

Other than that, I would need a bit more documentation. I do not know what the -1 value for .show indicates or why you are testing for it.


You could always have your dialog box get the values from the content controls and if they are empty require input (and then save the input to those controls).
Reply With Quote
  #7  
Old 03-19-2014, 03:21 AM
Catty Catty is offline Disabling Word's Save and SaveAs commands Windows 7 32bit Disabling Word's Save and SaveAs commands Office 2010 32bit
Advanced Beginner
Disabling Word's Save and SaveAs commands
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

Hi,

Thanks for all the feedback. My macro intercepts word's commands FileSave and FileSaveAs perfectly for word 2007 and 2010. It also works perfectly for 2013 FileSave but NOT for FileSaveAs.

I don't understand why this should be the case because the FileSaveAs command in 2013 is the same as 2010. Could I be doing something wrong? Are there any extra commands I should be putting in?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling Word's Save and SaveAs commands When I try to save an existing word doc, save as pops up and will not save... samanthab Word 3 01-19-2013 06:27 AM
Disabling Word's Save and SaveAs commands Saveas error handling jillapass Word VBA 7 03-30-2012 03:24 PM
Keyboard Commands korric Word 3 02-09-2012 12:52 AM
Disabling Word's Save and SaveAs commands saveAs ChDir _ tinfanide Excel Programming 4 11-05-2011 01:40 AM
Advance Commands Richard1 Word 0 02-10-2011 01:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 AM.


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