|
-
Aug 3rd, 2006, 11:33 AM
#1
Thread Starter
Hyperactive Member
[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
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?
-
Aug 3rd, 2006, 02:45 PM
#2
Thread Starter
Hyperactive Member
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:
Word cannot save this file because it is already open elsewhere.
C:\Doc.....Normal.dot.
aaargh! What did I do now...
-
Aug 3rd, 2006, 07:16 PM
#3
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
-
Aug 7th, 2006, 04:55 PM
#4
Thread Starter
Hyperactive Member
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:
Word cannot save this file because it is already open elsewhere.
C:\Doc.....Normal.dot.
What about adding?
-
Aug 7th, 2006, 06:26 PM
#5
Re: Modifying the footer in Word via VB6: The remote server machine does not exists...
 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.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 15th, 2006, 07:06 PM
#6
Thread Starter
Hyperactive Member
Re: Modifying the footer in Word via VB6: The remote server machine does not exists...
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|