[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:
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.Find.ClearFormatting
With Selection.Find
.Text = "REPORTING: "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
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:
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
Quote:
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? :confused:
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:
With moDoc.Application
If .ActiveWindow.View.SplitSpecial <> wdPaneNone Then
.ActiveWindow.Panes(2).Close
End If
If .ActiveWindow.ActivePane.View.Type = wdNormalView Or .ActiveWindow.ActivePane.View.Type = wdOutlineView Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If .Selection.HeaderFooter.IsHeader = True Then
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
.Selection.Find.ClearFormatting
With .Selection.Find
.Text = "REPORTING: "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Selection.Find.Execute
.Selection.MoveRight Unit:=wdCharacter, Count:=1
.Selection.TypeText Text:=" " & strName & " DATE: " & Date
End With
Now I get this:
Quote:
Word cannot save this file because it is already open elsewhere.
C:\Doc.....Normal.dot.
aaargh! What did I do now...
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
Re: Modifying the footer in Word via VB6: The remote server machine does not exists...
Code for opening:
VB Code:
Set moApp = New Word.Application
Set moApp = CreateObject("Word.Application")
Set moDoc = moApp.Documents.Open(App.Path & "\reports\Offense.doc")
Code for closing:
VB Code:
moDoc.Close False
Set moDoc = Nothing
DoEvents
Dim n
For n = 1 To 100000#: Next n
NormalTemplate.Saved = True
moApp.Quit False
Set moApp = Nothing
This is the problem I'm still getting:
Quote:
Word cannot save this file because it is already open elsewhere.
C:\Doc.....Normal.dot.
What about adding?
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:
Set moApp = New Word.Application
Set moApp = CreateObject("Word.Application")
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.
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 :confused:
I had tested both methods, some how much have removed the comment delimiter ' removing the commented out line, duh...
Thanks RobDog888 :wave: