Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

"on save" macro launching

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dariusz Tomon - 13 Nov 2006 22:20 GMT
Hello

The problem is like this:

All I want is to launch a macro when user saves document. Macro should check
if a defined string is present in footer of document. If not - the macro
should open info form with possibility to enter missing string (string = id
+ date + sth... of document).
Please provide a sample of code or redirect me to appropriate page when I
could read how to realize it.

Best Regards

Dariusz Tomon
Andrew V - 14 Nov 2006 03:17 GMT
Assuming I read your request properly, the code below may help your efforts.  
It overrides the built-in Save function.  One bug in the code below is that
it crashes if the Save As dialog comes up and the user hits Cancel.  But
that's what error-handling is for.

Sub FileSave()
   
   'The following line defines the string expected in the footer
   Const REQUIRED_STR = "Put defined string here"
   
   With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
   
       'Check footer text (first section main footer only)
       If InStr(1, .Text, REQUIRED_STR) = 0 Then
       
           'Prompt user for footer text
           Dim newStr As String
           newStr = InputBox("Footer text should include '" & REQUIRED_STR
& "'.  Enter new footer text:", "Enter string")
           
           If newStr = "" Then 'User didn't input any text, so abort save
procedure
               Exit Sub
           Else 'Place specified text into footer
               .Text = newStr
           End If
       End If
       
   End With

   'Save file
   ActiveDocument.Save

End Sub

> Hello
>
[quoted text clipped - 10 lines]
>
> Dariusz Tomon

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.