I want to write a macro that only works in one word document

Ron147

I've got this macro in MS Word 2016. It works in every word document, but I want it to work in only one word document eg 'Test.docx'. Can I add something to the code to do this?

The macro in question is this:

Sub MyMistakesFinal()
'
' MyMistakesFinal Macro
'
'
    Selection.Find.ClearFormatting
    With Selection.Find.Font
        .Bold = True
        .Underline = wdUnderlineSingle
    End With
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Previous(Unit:=wdParagraph, Count:=1).Select
End Sub
Domenic

You can test whether the active document is "Test.docx". If not, exit the sub...

Sub MyMistakesFinal()
'
' MyMistakesFinal Macro
'
'
    If ActiveDocument.Name <> " Test.docx" Then Exit Sub

    'etc
    '
    '
    '

End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I want a Word macro to be only associated with a specific .docm file

Want to read only one document

I want to convert Arabic numerals “٠,١,٢,٣,٤,٥,٦,٧,٨,٩” from whole document into English numerals using Word Macro?

Word VBA macro button only works once

Excel: Macro affects multiple columns in table when I only want it to affect a specific one

i want to toggle between two functions this code works only one time but i want to make it work each time i click

Context Menu (RightClickMenu) Excel: Works only in one book, I want it to work everywhere

Embed Macro in Document Word

How to I get the right output when there is more than vowel in each word? My code only works with one vowel in each word

How can I remove all Hyperlinks from a Word document with a macro?

Document.write won't display what I want

Macro works in Word 2013, but not in 2010

Run word macro on keypress in document

W2VTransformer: Only works with one word as input?

Function only works how I want it with print, not return

HTML parsing with beautifulsoup works on most URL except the one I want

wavfile.write: Identical arrays but only one works

NodeJS FileSystem Json Read and Write only one works

Set Word = GetObject(, "Word.Application") works in one sub, but not in other sub in same document

Can i write two foreach in only one?

I want to write only method names in notepad with using eclipse in java

Macro works fine copting data until it finds duplicate. I want it to copy the duplicate

I want to express the below "I have only one of the two" in TypeScript

I want to write multiple queries results one after another in oracle

How do I unlock a read-only Word document form?

How to make macro enabled Word document back into a normal word document?

No able to delete the record I want, only the first one

Problem with list all dfs files, i want to select only one

sql server (Two tables and I want to display only one row)