Variable not set

D

DESPERATE IN MS

Can some please tell me what I'm missing or what I have wrong.

Here is my code for embedding documents:
Public Sub WOHdrFtr()
'
' Work Oder Header Macro
' Macro recorded 3/17/2009 XXXXXXXXXXXXXXXXXXXXX(data is good)
'
Dim wrdDoc As Word.Document
Selection.InsertFile FileName:="O:\Routine Maintenance\Routine Planner
Share\Common\Macros\Docs\WoHdrFtr.doc", Range:="", ConfirmConversions _
:=False, Link:=False, Attachment:=False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
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


End Sub

The VB code is in a custom template I have created with a custom toolbar
assigned to each new document which is ran by the VB code.

The word template "embeds" these documents and saves as a ole to a server.

This all is working fine except I get an error "91" Objext variable or With
Block variable not set on " Selection.InsertFile FileName:="O:\Routine
Maintenance\Routine Planner
Share\Common\Macros\Docs\Clay\EnergyWeldAApecStic.doc", Range:="",
ConfirmConversions _:=False, Link:=False, Attachment:=False
 
D

Doug Robbins - Word MVP on news.microsoft.com

Assuming that "O:\Routine Maintenance\Routine Planner
Share\Common\Macros\Docs\WoHdrFtr.doc" is a valid path\document, there is
nothing wrong with your Selection.InsertFile command, except that there may
not be an active selection at the time that it is being run.

I do not understand the purpose of the

Dim wrdDoc As Word.Document

when you do not appear to be using a Set wrdDoc = to set wrdDoc to a
document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top