Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    W97 template into WXP (WinNT/Word97)

    I have a number of templates developed in Word 97 that developed a strange behaviour when used in Word 2k or Word XP. They each end their initial setup by saving themselves under names concatenated from info gathered in input boxes and in a directory specified in the code.

    This worked perfectly in 97, but when I pulled them into Word 2000 (a very late Beta) - they ran perfectly until the first input box, when the Word window behind the box suddenly vanished, then carried on working (ie I could only see the input boxes themselves, but each came up in turn on request - it looked rather pretty against my background photo) until the last box was done, when everything to do with Word vanished and could not be found. Ctrl-Alt-Del showed Word running but would not bring it up, and if I opened a new copy of Word and opened the newly saved document it was there and perfectly formed. Weird, I thought - but it was personal stuff, and since it was a beta of Word I assumed it was something to do with that.

    Then I upgraded to Office XP SP1 - and the same thing happened, with the minor adjustment that when I opened a new copy of Word the newly created document was there on the Window menu - ie still open. So it's not either Word 2000 or the fact that it was a beta.

    Has anyone else come across this? Or is there something slightly different in the VBA of Word 2000+ that would stop it happening? The reason I ask specifically now (I've been working around it at home for sometime without worrying about it) is that we're going to Win2003/Office2003 at work in the new year and a good proportion of the 2000+ templates I maintain have save routines, so I'm going to have to find out what does this and sort it out!

    Help please! <img src=/S/help.gif border=0 alt=help width=23 height=15>
    Beryl M


  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: W97 template into WXP (WinNT/Word97)

    Well... I think we'd need to see whether you were minimizing, closing, or hiding anything in your code. That certainly is not the expected behavior from simply displaying an InputBox, and if Word was crashing, one would expect a message (or the VB executor would freeze up, too).

    In Word 2002/2003, does it make any difference if you clear the "Windows in Taskbar" checkbox under Tools>Options>View?

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: W97 template into WXP (WinNT/Word97)

    Hi Jefferson - well, clearing 'Windows in Taskbar' didn't make any difference (what does that do, by the way?) and this is the code, followed by copies of the functions used in it (which are stored in Normal). The screen blanks after the second 'ask':
    <pre>Sub document_new()
    Dim PBPMNo As String, PBPMmonth As String

    PBPMNo = Ask("PBPM issue no:")
    PBPMmonth = Ask("PBPM Publication Month (mmmyy)")

    TxtReplace "#no", PBPMNo
    TxtReplace "#inv", Ask("Invoice no (issue no will be added automatically):")

    Application.ScreenUpdating = False

    ActiveDocument.ActiveWindow.ActivePane.View.SeekVi ew = wdSeekCurrentPageFooter
    ActiveDocument.ActiveWindow.ActivePane.View.NextHe aderFooter
    With Selection.Find
    .Text = "#no"
    .Replacement.Text = PBPMNo
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveDocument.ActiveWindow.ActivePane.View.SeekVi ew = wdSeekMainDocument

    GoToBk "Spiral"

    ChangeFileOpenDirectory "C:datawpdocspuzzles - free 'n' easy"
    ActiveDocument.SaveAs FileName:="PBPM" + PBPMNo + " (" + PBPMmonth + ") sent .doc", _
    FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
    AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
    EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    SaveAsAOCELetter:=False

    Application.ScreenUpdating = True

    Application.Browser.Target = wdbrowsepage

    End Sub</pre>

    <pre>Public Function Ask(Question As String, Optional Default As String, _
    Optional allowEmpty As Boolean = False) As String
    Ask = InputBox(Question, "Standard Letters", Default)
    If (Ask = Empty) And (allowEmpty = False) Then Ask = "..............."
    End Function</pre>

    <pre>Public Sub TxtReplace(Txt_From As String, Txt_To As String)

    If Not Exist(Txt_From) Then Exit Sub

    If Txt_To = "" Then
    FiRep Txt_From & " ", Txt_To
    FiRep " " & Txt_From, Txt_To
    End If
    FiRep Txt_From, Txt_To
    End Sub</pre>

    <pre>Private Sub FiRep(fnd As String, rep As String)
    With ActiveDocument.Range.Find
    .ClearFormatting
    .Text = fnd
    .Replacement.Text = rep
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    End With

    End Sub</pre>

    <pre>Public Function Exist(Test_To_Check As String) As Boolean
    Set rng = ActiveDocument.Range
    With rng.Find
    .ClearFormatting
    .Text = Test_To_Check
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
    End With
    Exist = (rng.Text = Test_To_Check)
    Set rng = Nothing
    End Function</pre>


    As you can see, there is nothing there that could be causing the symptoms I'm getting - at least, I can't see anything!

    Any help would be greatly appreciated!
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: W97 template into WXP (WinNT/Word97)

    If "Windows in Taskbar" is checked, each document you open behaves as if it lives in a separate instance of Word - each one gets its own icon in the Windows task bar, you can switch between them using Allt+Tab, etc. This behavior was introduced in Word 2000, and since it annoyed many users, Microsoft decided to make it optional in Word 2002.
    If "Windows in Taskbar" is unchecked, Word behaves more or less as in Word 97.

    I am using Word 2002 SP-2 (Dutch).

    I copied your code to a new template. I commented out GoToBk "Spiral" since GoToBk is not defined on my system, and the ChangeFileOpenDirectory instruction (by the way, how nice to store invoices in a folder named puzzles - free 'n' easy.) And I inserted the missing line Dim rng As Range in the Exist function (you do have Option Explicit in all your modules, I hope?) I inserted some dummy text in the template, and created headers and footers, and put in some random #no's and #inv's. I saved the template, and created a new document from it. I got asked for three items, the replacements took place and the document was saved correctly. So the problem doesn't seem to be in the code you posted.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: W97 template into WXP (WinNT/Word97)

    Hi again Hans - thanks for the help. Sorry about GoToBk - it's another mini function in Normal that just goes to a bookmark! and yes, I do use Option Explicit - rng is defined in the original template, but it's global so it isn't dimmed within that sub.

    Actually, the template is some 13 pages long, with only the first page being an invoice, the rest being various puzzles - I compile for various publications, one of which was called 'Free 'n' Easy' (it's now changed it's name, but I couldn't be bothered to changed the directory and code just for that!), hence the directory name!

    I'm glad you agree there's nothing in the code - I couldn't spot anything myself but was beginning to think I was missing something since it carried on behaving like that when I got XP! I'd thought it was something to do with the beta of 2000 until the problem carried on after upgrading! It's not something that got carried over between versions, either, because I've since had a catastrophic computer failure that trashed my entire hard disk so I had to start again from scratch and there's nothing of Office on this machine earlier than XP now.

    Maybe it's something outside Office, do you think? But where on earth would I start looking, if so?!

    (About the only good t hing about the fact that you've confirmed it's not the code is that it makes it highly unlikely that we'll get the same problem when we upgrade at work! <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16> )
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: W97 template into WXP (WinNT/Word97)

    You might try to unload all global templates / add-ins, and see if it works OK then. If so, the cause of the problem must be in one of the global templates / add-ins. By activating them one by one, you should be able to find the culprit. If not, it's hard to guess...

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: W97 template into WXP (WinNT/Word97)

    I didn't actually test this, but what do you get if you instrument your code to update the status of the visibility of the ActiveDocument.ActiveWindow?
    <pre>Sub document_new()
    Dim PBPMNo As String, PBPMmonth As String

    PBPMNo = Ask("PBPM issue no:")
    PBPMmonth = Ask("PBPM Publication Month (mmmyy)")
    UpdateVisibility "Call to TxtReplace re: #no"
    TxtReplace "#no", PBPMNo
    UpdateVisibility "Call to TxtReplace re: #inv"
    TxtReplace "#inv", Ask("Invoice no (issue no will be added automatically):")
    UpdateVisibility "Turning off screen updating"
    Application.ScreenUpdating = False
    UpdateVisibility "Seeking current page footer"
    ActiveDocument.ActiveWindow.ActivePane.View.SeekVi ew = wdSeekCurrentPageFooter
    ActiveDocument.ActiveWindow.ActivePane.View.NextHe aderFooter
    With Selection.Find
    .Text = "#no"
    .Replacement.Text = PBPMNo
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveDocument.ActiveWindow.ActivePane.View.SeekVi ew = wdSeekMainDocument

    GoToBk "Spiral"

    ChangeFileOpenDirectory "C:datawpdocspuzzles - free 'n' easy"
    ActiveDocument.SaveAs FileName:="PBPM" + PBPMNo + " (" + PBPMmonth + ") sent .doc", _
    FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
    AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
    EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    SaveAsAOCELetter:=False

    Application.ScreenUpdating = True

    Application.Browser.Target = wdbrowsepage

    End Sub

    Public Function Ask(Question As String, Optional Default As String, _
    Optional allowEmpty As Boolean = False) As String
    UpdateVisibility "Commencing Ask re: " & Question
    Ask = InputBox(Question, "Standard Letters", Default)
    If (Ask = Empty) And (allowEmpty = False) Then Ask = "..............."
    UpdateVisibility "Exiting Ask re: " & Question
    End Function

    Public Sub TxtReplace(Txt_From As String, Txt_To As String)
    UpdateVisibility "Call to Exist from TxtReplace re: " & Txt_From
    If Not Exist(Txt_From) Then Exit Sub

    If Txt_To = "" Then
    UpdateVisibility "First Call to FiRep from TxtReplace re: " & Txt_From
    FiRep Txt_From & " ", Txt_To
    UpdateVisibility "Second Call to FiRep from TxtReplace re: " & Txt_From
    FiRep " " & Txt_From, Txt_To
    End If
    UpdateVisibility "Third Call to FiRep from TxtReplace re: " & Txt_From
    FiRep Txt_From, Txt_To
    End Sub

    Private Sub FiRep(fnd As String, rep As String)
    UpdateVisibility "Commencing FiRep re: " & fnd
    With ActiveDocument.Range.Find
    .ClearFormatting
    .Text = fnd
    .Replacement.Text = rep
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    UpdateVisibility "Pre-execute re: " & fnd
    .Execute Replace:=wdReplaceAll
    UpdateVisibility "Post-execute re: " & fnd
    End With
    UpdateVisibility "Exiting FiRep re: " & fnd
    End Sub

    Public Function Exist(Test_To_Check As String) As Boolean
    UpdateVisibility "Commencing Exist re: " & Test_To_Check
    Set rng = ActiveDocument.Range
    With rng.Find
    .ClearFormatting
    .Text = Test_To_Check
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    UpdateVisibility "Pre-execute re: " & Test_To_Check
    .Execute
    UpdateVisibility "Post-execute re: " & Test_To_Check
    End With
    UpdateVisibility "Pre-assignment re: " & Test_To_Check
    Exist = (rng.Text = Test_To_Check)
    UpdateVisibility "Post-assignment re: " & Test_To_Check
    Set rng = Nothing
    UpdateVisibility "Exiting Exist re: " & Test_To_Check
    End Function

    Sub UpdateVisibility(strIdentifier as String)
    Debug.Print ActiveDocument.ActiveWindow.Visible & " @ " & strIdentifier
    End Sub
    </pre>

    Maybe we can find the point at which you're losing it. Or maybe this is a dead end?

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: W97 template into WXP (WinNT/Word97)

    Thanks, Jefferson, looks like it might help, but I'm not going to have time to try it for a couple of weeks (this thing called Christmas getting in the way again ...).

    I'll get back to you when I do get a chance to have a go!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •