Results 1 to 6 of 6

Thread: [RESOLVED] Modifying the footer in Word via VB6: The remote server machine does not exists...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Resolved [RESOLVED] Modifying the footer in Word via VB6: The remote server machine does not exists...

    I am using this code posted by WebTest:

    VB Code:
    1. If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    2.         ActiveWindow.Panes(2).Close
    3.     End If
    4.    
    5.     If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    6.         ActivePane.View.Type = wdOutlineView Then
    7.         ActiveWindow.ActivePane.View.Type = wdPrintView
    8.     End If
    9.    
    10.     ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    11.    
    12.     If Selection.HeaderFooter.IsHeader = True Then
    13.         ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    14.     Else
    15.         ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    16.     End If
    17.    
    18.     Selection.Find.ClearFormatting
    19.    
    20.     With Selection.Find
    21.         .Text = "REPORTING: "
    22.         .Replacement.Text = ""
    23.         .Forward = True
    24.         .Wrap = wdFindContinue
    25.         .Format = False
    26.        .MatchCase = False
    27.         .MatchWholeWord = False
    28.         .MatchWildcards = False
    29.         .MatchSoundsLike = False
    30.         .MatchAllWordForms = False
    31.     End With
    32.    
    33.     Selection.Find.Execute
    34.     Selection.MoveRight Unit:=wdCharacter, Count:=1
    35.     Selection.TypeText Text:=" " & strName & "       DATE: " & Date

    It seeks out the footer in a template document I have set, and successfully prints the document, then closes the document and ms word.

    All seems fine until.... I print the next document. Then I get the following:

    At this line:

    VB Code:
    1. If ActiveWindow.View.SplitSpecial <> wdPaneNone Then

    Runtime error '462':
    The remote server machine does not exists or is unavailable
    All data inserted into the document succeds, it is when I modify the footer the second time. If I close and restart my application, then it prints fine the first time. Just fails on the footer insert on the second pass.

    This is driving me crazy, why is this happening?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Modifying the footer in Word via VB6: The remote server machine does not exists...

    One problem fixed:

    I need to reference the object, seems to get lost:

    VB Code:
    1. With moDoc.Application
    2.         If .ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    3.             .ActiveWindow.Panes(2).Close
    4.         End If
    5.        
    6.         If .ActiveWindow.ActivePane.View.Type = wdNormalView Or .ActiveWindow.ActivePane.View.Type = wdOutlineView Then
    7.             .ActiveWindow.ActivePane.View.Type = wdPrintView
    8.         End If
    9.        
    10.         .ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    11.        
    12.         If .Selection.HeaderFooter.IsHeader = True Then
    13.             .ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    14.         Else
    15.             .ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    16.         End If
    17.        
    18.         .Selection.Find.ClearFormatting
    19.        
    20.         With .Selection.Find
    21.             .Text = "REPORTING: "
    22.             .Replacement.Text = ""
    23.             .Forward = True
    24.             .Wrap = wdFindContinue
    25.             .Format = False
    26.             .MatchCase = False
    27.             .MatchWholeWord = False
    28.             .MatchWildcards = False
    29.             .MatchSoundsLike = False
    30.             .MatchAllWordForms = False
    31.         End With
    32.    
    33.         .Selection.Find.Execute
    34.         .Selection.MoveRight Unit:=wdCharacter, Count:=1
    35.         .Selection.TypeText Text:=" " & strName & "       DATE: " & Date
    36. End With

    Now I get this:

    Word cannot save this file because it is already open elsewhere.
    C:\Doc.....Normal.dot.

    aaargh! What did I do now...

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Modifying the footer in Word via VB6: The remote server machine does not exists...

    if possible, don't use activewindow, but refer to by it's specific name (or number), or the specific document.

    you don't show your code for closing the document or word, but if it elling you the document still open i would look at that
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Modifying the footer in Word via VB6: The remote server machine does not exists...

    Code for opening:

    VB Code:
    1. Set moApp = New Word.Application
    2.         Set moApp = CreateObject("Word.Application")
    3.  
    4.     Set moDoc = moApp.Documents.Open(App.Path & "\reports\Offense.doc")

    Code for closing:

    VB Code:
    1. moDoc.Close False
    2.     Set moDoc = Nothing
    3.    
    4.     DoEvents
    5.    
    6.     Dim n
    7.    
    8.     For n = 1 To 100000#: Next n
    9.     NormalTemplate.Saved = True
    10.    
    11.     moApp.Quit False
    12.     Set moApp = Nothing

    This is the problem I'm still getting:

    Word cannot save this file because it is already open elsewhere.
    C:\Doc.....Normal.dot.
    What about adding?

    VB Code:
    1. .NormalTemplate = False

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Modifying the footer in Word via VB6: The remote server machine does not exists...

    Quote Originally Posted by easymoney
    Code for opening:

    VB Code:
    1. Set moApp = New Word.Application
    2.         Set moApp = CreateObject("Word.Application")
    3.  
    4.     Set moDoc = moApp.Documents.Open(App.Path & "\reports\Offense.doc")
    You dont need to create a duplicate instance of word application. The use of the New keyword in the definition line will create it but shouldnt be used in that way. Better to use it with Set or just CreateObject.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Modifying the footer in Word via VB6: The remote server machine does not exists...

    Quote Originally Posted by RobDog888
    You dont need to create a duplicate instance of word application. The use of the New keyword in the definition line will create it but shouldnt be used in that way. Better to use it with Set or just CreateObject.
    Damn, that was simple. Deleted 1 line of code and all problems fixed. Can't believe I did not catch that

    I had tested both methods, some how much have removed the comment delimiter ' removing the commented out line, duh...

    Thanks RobDog888
    Last edited by easymoney; Aug 15th, 2006 at 10:33 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width