Consulting

Results 1 to 2 of 2

Thread: Loop thru all opened word documents

  1. #1

    Loop thru all opened word documents

    Hi all

    I want to loop thru all opened word documents but my code stays on the first selected file. It also only just loops 2 times even if I have more files opened.

    the code :

    Dim wd As Range

    For Each wd In ActiveDocument.Words

    wd.Select
    MsgBox (wd.Document.Name)
    'Do stuff

    next wd

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,339
    Location
    The code you posted has nothing to do with looping through all opened documents.

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oDoc As Document
      For Each oDoc In Documents
        MsgBox oDoc.Name
      Next
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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