PDA

View Full Version : Writing a macro in word to search footer for specific text



challengedvb
06-22-2007, 01:31 PM
Greetings,

I'm a newbie in writing vba code. My task is to write code/macro that would upon opening a document, prompt the user to view text in the document's footer and remove old text that doesn't belong.

Could someone help me with that?

Thanks in advance for you time!

lucas
06-22-2007, 03:39 PM
MsgBox "Change the footer!"
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

In the thisworkbook module in the workbook open procedure. See attached

challengedvb
06-25-2007, 07:15 AM
Thanks for posting. Is the code you sent for MS Excel or is it universal for all MS Office programs?

lucas
06-25-2007, 07:24 AM
I'm sorry...I don't do much in Word so I gave the wrong instructions. It should be

In the thisdocument module and the document open procedure:
Private Sub Document_Open()
MsgBox "Change the footer!"
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
End Sub

The file attached in post#2 is a Word documnent.....did you try it?

challengedvb
06-25-2007, 07:48 AM
Yes it works, but not exactly the way I need it to. I need Word to search for specific text in the footer and if the text is there, then I need the pop up box to appear. The way it's written now the pop up box will appear whenever a doc is opened.

lucas
06-25-2007, 07:51 AM
Sorry...I only had your post to go by......

My task is to write code/macro that would upon opening a document, prompt the user to view text in the document's footer and remove old text that doesn't belong

fumei
06-25-2007, 10:21 AM
You need to specify if you have multiple footers. Do you have DifferentFirstPage? DifferentOddEven?

Do you have multiple Sections? Each Section has its own footers. Are you only searching for text in Section 1? Other Sections?

In other words...WHAT (or rather WHICH) footer are you wanting to search?

Other than that, this is pretty easy to do. You did, in fact, make somewhat confusing statements in your first post.

"that would upon opening a document" - sure seems like you want to have the procedure fire when the document opens...yes?

"prompt the user to view text in the document's footer" - prompt is prompt, and "view" is view

"and remove old text that doesn't belong" - Belong???? Funny, I see no logic, or parameters, for determining what belongs...or does not belong. Not to be sarcastic, but is the macro supposed to, by itself, understand what does, or does not "belong"? You may be asking too much of VBA.

Let me see if I can rewrite your post....

I need a macro that will:

1. on document open, retrieve the text in the existing footer of Section 1. The document does not have different footers for that Section. I only want Section 1 checked.

2. the retrieved text is to be checked against a given text string.

3. if it is the same, do nothing else and the document opens normally.

4. if it is different, I want the existing text to be displayed, along with an input box for the user to be able to input new text.

5. any text the user inputs will REPLACE the existing text, not AMEND any portion of the existing text.

There....am I close?

Better specs....better code.