View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Jackson Jim Jackson is offline
external usenet poster
 
Posts: 324
Default Opening doc in macro

I think you have too many sets of quotemarks in places. This could be
causing a problem.

Instead of """Referal Agency - Ecology.doc""" "Referal Agency - Ecology.doc"

Also, be sure you have spelled document names exactly as they are spelled.
--
Best wishes,

Jim


"Michelle Hanan" wrote:

Sorry I'm a beginner and I don't know if I keyed this in correctly..it's not
working. I keep getting Compile error: User-defined type not defined

This is the code that I am trying to run and it's not working.

Dim myDoc As Word.Document
Dim oWd As Word.Application, oWdoc As Word.Document
Set myDoc = Word.Documents.Open("C:\MyFiles\MyDoc.doc")
Set oWd = CreateObject(("\\powervault2\home_pl\common\referr als\"))
Set oWdoc = oWd.Documents.Add
Documents.Open Filename:="""Referal Agency - Ecology.doc""", _
ConfirmConversions:=True, ReadOnly:=False, AddToRecentFiles:=False,
_
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\powervault2\home_pl\common\Referrals\Referals.x ls",
ConfirmConversions _
:=False, ReadOnly:=False, LinkToSource:=True,
AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto,
_
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us er ID=Admin;Data
Source=\\powervault2\home_pl\common\Referrals\Refe rals.xls;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet
OLEDB:Registry Path="""";Jet OLEDB:Database Password=" _
, SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="",
SubType:= _
wdMergeSubTypeAccess
With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
ActiveWindow.Close

"tony h" wrote in
message ...

try

Dim myDoc As Word.Document

Set myDoc = Word.Documents.Open("C:\MyFiles\MyDoc.doc")

remember to reference the word object library


--
tony h
------------------------------------------------------------------------
tony h's Profile:
http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=560754