Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Rockford, Illinois, USA
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Running a macro on multiple docs at the same time (Word 97 SR2)

    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?

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    Here's a stripped-down means to do this:

    <pre>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
    </pre>

    Gary

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Rockford, Illinois, USA
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    I tried the macro after inserting my watermark macro, but I get a compile error. What am I doing wrong? Attached is your macro with my macro inserted.
    Attached Files Attached Files

  4. #4
    New Lounger
    Join Date
    Jul 2001
    Location
    D.C.
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    I'm no expert, but it looks to me as if there is a space before the first parenthesis (after ".Open") in the line
    Documents.Open (.FoundFiles(i))
    Would that cause a compile error?

    Rick Ellrod

  5. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    You have a Sub within a Sub. Remove the "Sub WaterMark ()" line and the first "End Sub" line (the one right before Activedocument.Close (wdSaveChanges)).

    HTH,

    Chris

  6. #6
    Lounger
    Join Date
    Jan 2001
    Location
    Rockford, Illinois, USA
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    Thanks for the help everyone! It works like a charm!

    Can the macro be modified to not add the watermark if it is already there?

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    The 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:

    <pre> 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(msoTextOr ientationHorizontal, _
    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(msoTex tEffect2, "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
    </pre>

    Gary

  8. #8
    Lounger
    Join Date
    Jan 2001
    Location
    new orleans, louisiana
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    hi, what are the changes in code for the macro(s) to run in 2000?

  9. #9
    Lounger
    Join Date
    Jan 2001
    Location
    Rockford, Illinois, USA
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    Thanks Gary. I will give it a try.

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    Hi Kathleen,

    It looks like this code should run in 2000 as well without revision.

    Gary

  11. #11
    Lounger
    Join Date
    Jan 2001
    Location
    new orleans, louisiana
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    OK, 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?

  12. #12
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    Hi 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

  13. #13
    Lounger
    Join Date
    Jan 2001
    Location
    new orleans, louisiana
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    OK, 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!

  14. #14
    Lounger
    Join Date
    Jan 2001
    Location
    Rockford, Illinois, USA
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    I 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.

  15. #15
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Running a macro on multiple docs at the same time (Word 97 SR2)

    I 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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •