the macro below works fine in Word 2000 premium but does not work in Word XP 2002.
What happens in the macro is that it takes some text and applies it to a template, it opens up the new window but the macor falls over with an error of
runtime error 5941
when it runs the Windows(1).Activate line, when it tries to switch to the original window.
Many thanks in advance.
What happens in the macro is that it takes some text and applies it to a template, it opens up the new window but the macor falls over with an error of
runtime error 5941
when it runs the Windows(1).Activate line, when it tries to switch to the original window.
Many thanks in advance.
Code:
Sub Purchase()
'
' Despatch Purchase
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Continue"
.Replacement.Text = "Continue(PAGEBREAKHERE)"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "\\********\data\global\logo"
Documents.Open FileName:="POTEMPLATE.dot", ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.BuiltInDocumentProperties("Title") = "Second"
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Font.Name = "Courier New"
Selection.Font.Size = 9
Windows(1).Activate
Selection.WholeStory
Selection.Copy
Windows(2).Activate
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False
Windows(1).Activate
ActiveWindow.Close
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^m"
.Replacement.Text = "(PAGEBREAKHERE)"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(PAGEBREAKHERE)"
.Replacement.Text = "^m"
.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:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.TypeText Text:=" "
Selection.HomeKey Unit:=wdLine
End Sub
Sub enquiry()
'
' panda Macro
'
Selection.TypeText Text:="Good "
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:= _
"Please can you supply me with a price and availability for t"
Selection.TypeText Text:="he following:"
Selection.TypeParagraph
Selection.TypeParagraph
End Sub