View Single Post
 
Old 10-31-2012, 05:55 PM
marceepoo marceepoo is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Sep 2012
Posts: 22
marceepoo is on a distinguished road
Default Ensure macro operates in the right doc window

Assume that I am working in Word 2010, and
I have two Word documents open, Doc1 and Doc2, and
I am editing Doc1.

Sometimes, when I am working in Doc1, and I click on the button that triggers the macro below "subCurlyQuots", the macro will operate on Doc2 instead of Doc1.

How can I make sure that the macro operates on Doc1 instead of Doc2?

Any help would be much appreciated.

Thanks,

Marc
Code:
Sub subCurlyQuots() ' ' CurlyQuotes Macro ' ' ActiveDocument.ActiveWindow.SetFocus With ActiveDocument.Bookmarks .Add Range:=Selection.Range, Name:="CurlyQuotes99999999999999" .DefaultSorting = wdSortByName .ShowHidden = False End With Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = """" .Replacement.Text = """" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "'" .Replacement.Text = "'" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.GoTo What:=wdGoToBookmark, Name:="CurlyQuotes99999999999999" ActiveDocument.Bookmarks("CurlyQuotes99999999999999").Delete With ActiveDocument.Bookmarks .DefaultSorting = wdSortByName .ShowHidden = False End With End Sub ' subCurlyQuots()

Last edited by macropod; 10-31-2012 at 08:54 PM. Reason: Added code tags & formatting
Reply With Quote