VBA to Target Specific Open Word 2010 Files

I'm trying to automate a number of tasks required to modify Word 2010 files.

I want to assign individual macros to active-X buttons in a controller file (e.g. controlFile.dotm) which I will keep open beside the Word files i am modifying (I have macro snippets currently in normal.dotm)

I can create the controller file, buttons and link them to VBA snippets (by copying the snippets into controlFile.dotm)

The Word files I wish to target will already be Open on my desktop and all have a defined filename structure which contains a specific string, say 'sometextABCsometext'

In addition to the open Word files I'm targeting, i need to have other Word files open which I don't want to target with the VBA snippets, say 'leavemealone1.docx' and 'leavemealone2.docx'

How can I get the macros to act on any Word file whose filename contains the string 'ABC' but not work on other Word files which might be open at the time?
qengAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
You would need some code like this:
Sub WorkOnABCDocs()
    Dim doc As Document
    For Each doc In Documents
        If doc.Name Like "*ABC*" Then
            ProcessMe doc
        End If
    Next doc
End Sub

Open in new window

0
qengAuthor Commented:
Hi Graham,

I can get my open Word document to list correctly (as a test) with the following code:
-------------
    For Each doc In Documents
        If doc.Name Like "*ABC*" Then
            MsgBox "ABC=" & doc.Name
           
            Call Set_Review_Final
        End If
    Next doc
-----------------

But when the line calls Sub 'Set_Review_Final' (below):
-----------------
Sub Set_Review_Final()
'
' Set_Review_Final Macro
' Sets Track Changes to Final
'
    ActiveDocument.TrackRevisions = Not ActiveDocument.TrackRevisions
    With ActiveWindow.View
        .ShowRevisionsAndComments = False
        .RevisionsView = wdRevisionsViewFinal
    End With
End Sub
----------------------

It seems to continue targeting the controller file instead of the file whose name is doc.Name.

How can I cause the macros to execute on doc.Name?
0
GrahamSkanRetiredCommented:
That is because your code works on the ActiveDocument, and not on the one found. You have two options. Firstly, activate the document found. Secondly and better, work on the found document without activating it.
Sub ProcessDoc(Doc As Word.Document)
'
' Set_Review_Final Macro
' Sets Track Changes to Final
'
    Doc.TrackRevisions = Not Doc.TrackRevisions
                        'Note. Are you sure that you want to toggle
                        'the TrackRevisions settings here? You might be better of just settting to on
                        'TrackRevisions = True
                        'or off TrackRevisions = True

    With Doc.ActiveWindow.View
        .ShowRevisionsAndComments = False
        .RevisionsView = wdRevisionsViewFinal
    End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
I've requested that this question be closed as follows:

Accepted answer: 500 points for GrahamSkan's comment #a40816308

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.