We have about 1500 documents that we are adding a watermark to. We have recorded a macro to add the watermark to the document. We open the document, run the macro, save, and close the document. This is getting very boring. Is there a way to run the macro on all documents or multiple documents at the same time?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Running a macro on multiple docs at the same time (Word 97 SR2)
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Running a macro on multiple docs at the same time (Word 97 SR2)
- This topic has 17 replies, 7 voices, and was last updated 23 years, 5 months ago.
Viewing 0 reply threadsAuthorReplies-
WSGary Frieder
AskWoody LoungerOctober 16, 2001 at 4:48 am #546933Here’s a stripped-down means to do this:
Public Sub InsertWatermarksInMultipleDocs() Dim sPath As String Dim i As Long sPath = InputBox("Type Path for Folder to be Searched") With Application.FileSearch .NewSearch .LookIn = sPath .FileType = msoFileTypeWordDocuments If .Execute > 0 Then For i = 1 To .FoundFiles.Count Documents.Open (.FoundFiles(i)) 'Your code to insert watermarks here '################################# ActiveDocument.Close (wdSaveChanges) Next 'i Else: MsgBox prompt:="Folder not found. Check path and try again." Exit Sub End If End With End Sub
Gary
-
erh3
AskWoody Lounger -
WSREllrod
AskWoody Lounger -
WSChris Green
AskWoody Lounger -
erh3
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerOctober 17, 2001 at 8:03 am #547182The following is a very quick and dirty amendment to your code so that it will only run if there is no graphic object (Shape) in the header/footer:
If ActiveWindow.View.SplitSpecial wdPaneNone Then ActiveWindow.Panes(2).Close End If If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ ActivePane.View.Type = wdOutlineView Or ActiveWindow.ActivePane.View.Type _ = wdMasterView Then ActiveWindow.ActivePane.View.Type = wdPageView End If ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader If Selection.HeaderFooter.IsHeader = True Then ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter Else ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader End If Dim rngTemp As Range Selection.WholeStory Set rngTemp = Selection.Range On Error Resume Next If rngTemp.ShapeRange.Count = 0 Then Selection.HeaderFooter.Shapes.AddTextbox(msoTextOrientationHorizontal, _ 72#, 676.8, 468#, 115.2).Select Selection.ShapeRange.TextFrame.TextRange.Select Selection.Collapse Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Line.Visible = msoFalse Selection.HeaderFooter.Shapes.AddTextEffect(msoTextEffect2, "History", _ "Times New Roman", 96#, msoFalse, msoFalse, 161.7, 401.15).Select Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192) Selection.ShapeRange.Fill.Visible = msoTrue Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Select Selection.ShapeRange.IncrementLeft 11.1 Selection.ShapeRange.IncrementTop -98.75 End If Set rngTemp = Nothing ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Gary
-
WSKathleen
AskWoody Lounger -
WSGary Frieder
AskWoody Lounger -
WSKathleen
AskWoody LoungerOctober 17, 2001 at 5:36 pm #547276OK, i’m on a network, i typed in the entire path and the macro had a good time looking for documents. it listed a bunch as it went thru them, but none were known to me nor the ones in the path i gave it.
long prelude, question-is it because i’m on a network and there are like several shared directories?
-
WSGary Frieder
AskWoody LoungerOctober 18, 2001 at 4:29 am #547372Hi Kathleen,
It’s really hard to tell what’s going on in that case.
When you say it listed the docs as it went through them, what do you mean? – do you mean the name of the document displays on the status bar, or what exactly?I’m not much of a network whiz so am not sure what effect shared directories would have.
Try the following: try having the macro search for files in a directory that’s on your local drive.
If it works OK to find files on your local drive, but not on a networked drive, then that would point to a network issue.Hope that helps,
Gary -
WSKathleen
AskWoody LoungerOctober 18, 2001 at 1:27 pm #547433OK, cool. the status bar says ‘opening’ then lists the files its going thru; on the network directory it listed main.htm and panasonic.html. no clue what they are. i tried it on the c drive and (after deleting one line of duplicate rngTemp) it whipped thru the files stamping history and a box! really cool! i’ll fiddle to see what else i can do in place of the graphic! since most docs are in the network, i’d really like ideas for using on that!
thanks for the help!
-
erh3
AskWoody LoungerOctober 18, 2001 at 1:36 pm #547436I tried the macro on the network too. It still put a graphic on the documents that already contained the watermark. I am not sure why it puts the gray box on the docs. I am going to redo the watermark part, since I may have made a mistake when I recorded it. Why would it still put the watermark on docs that already contain it? I will be using this on the network though, if that makes a difference.
-
WSjscher2000
AskWoody LoungerOctober 19, 2001 at 5:35 am #547628I can’t get the ShapeRange property of the Selection object to work either.
The following property gives an accurate count, but you need to find a way to know where you are (header or footer and which one):
Selection.Range.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.Count
Too late tonight to figure it out.
-
erh3
AskWoody Lounger -
erh3
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerOctober 25, 2001 at 6:01 am #548507Hi again,
The statement towards the beginning of the procedure:
Documents.Open(.FoundFiles(i))
opens the document, and the statement towards the end:
ActiveDocument.Close (wdSaveChanges)
should be serving to close it.
That’s usually a reliable enough way to specify the correct document you want the code to be working on, but if it’s not working, a couple of other means can be used:Documents.Close(.FoundFiles(i))
should work more reliably since it refers to the document by index (caveat that I haven’t tested it with your procedure).
An even more reliable method is to create an object variable and set it to equal the document as it opens:
Dim objDoc As Document
Set objDoc = Documents.Open (.FoundFiles(i))and then later one you use:
objDoc.Close (wdSaveChanges)
Set objDoc = NothingWith regard to the other post about the watermark getting inserted in documents that already have it – the code I suggested relied on getting a count of existing shapes in the header or footer.
This isn’t really reliable – as Jeff pointed out in his note – as it’s hard to get a count of shapes, particularly if the code isn’t specific as to whether you’re in the header or footer.
So the code would need to be more specific that way.Probably a more reliable way to test for the existence of a watermark in the document, would be to have the insert watermark code finish by adding either a bookmark or custom document property to the document (for example adding a boolean (Yes or No) “HasWatermark” custom document property and setting its value to Yes.
Then, the insert watermark procedure would first test for the existence of this custom document property, and whether its property was set to Yes.
There’s been some code posted here recently for adding custom doc props as well as testing whether one already exists – a search on this forum (or possibly the VBA forum) should turn up more info.
Gary
-
-
-
-
-
WSsolomod
AskWoody LoungerNovember 2, 2001 at 7:03 am #549780Hi Gary
Just like to say a big thank you for putting up the batch operation macro. I’ve never understood public macros and furthermore I have a huge number of docs where the paper source box has to be changed to Auto. I have just inserted my own box-change macro and whizzed through nearly half of them.
Many thanks.
David Solomon
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Oracle kinda-sorta tells customers it was pwned
by
Nibbled To Death By Ducks
4 hours, 46 minutes ago -
Global data centers (AI) are driving a big increase in electricity demand
by
Kathy Stevens
15 hours, 6 minutes ago -
Office apps read-only for family members
by
b
17 hours, 42 minutes ago -
Defunct domain for Microsoft account
by
CWBillow
14 hours, 34 minutes ago -
24H2??
by
CWBillow
4 hours, 46 minutes ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
1 day, 2 hours ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
2 hours, 37 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
14 hours, 31 minutes ago -
two pages side by side land scape
by
marc
2 days, 15 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
2 days, 17 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
1 day, 20 hours ago -
Security Essentials or Defender?
by
MalcolmP
1 day, 23 hours ago -
April 2025 updates out
by
Susan Bradley
4 hours, 13 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
1 day, 16 hours ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
1 day, 6 hours ago -
Creating an Index in Word 365
by
CWBillow
2 days, 9 hours ago -
Coming at Word 365 and Table of Contents
by
CWBillow
21 hours, 14 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
3 days, 12 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
3 days, 16 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
3 days, 17 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
3 days, 15 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
3 days, 9 hours ago -
I installed Windows 11 24H2
by
Will Fastie
1 day, 15 hours ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
3 days, 21 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
14 hours, 40 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
4 days, 5 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
3 days, 13 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
3 days, 14 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
4 days, 22 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
5 days, 7 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.