Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word macro--does not work in different verisons

Status
Not open for further replies.

nicklieb

Programmer
Oct 17, 2002
383
GB
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.


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
 
Hi

I am wondering if perhaps you have multiple document interface (MDI) in XP. This will open multiple documents in a single window. To check this choose Tools, Options, View; and ensure that the Windows in Taskbar check box is checked.
Its a long shot, I know.

Jens Busse
Workflow Consultant
CCI Europe A/S
 
thanks for the reply, but that option is checked.

I have to admit that I'm a complete novice to VBA in word.

any more suggestions please?

 
What about forcing the previous window to close before opening the new windows - it seems that the previous window has the focus....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top