Re: Open or Create word document from within Access
- From: Cindy M -WordMVP- <C.Meister-C@xxxxxxxxxx>
- Date: Wed, 13 Apr 2005 17:44:12 +0200
Hi =?Utf-8?B?cmljaGFyZGI=?=,
> I have attempted to write a routine in Access that will test if a Word file
> exists; create if it does not exist; then open it for editing. I can't quite
> get it. I get the error message "Invalid use of New keyword." (I attached the
> Word 11 Object Library). I would appreciate if someone wouldn't mind
> debugging this for me.
>
I'm inserting the commment 'HERE where I'd change things
Public Function OpenFile(strFileName As String)
Dim wrd As Word.Application
Dim doc As Word.Document ''HERE
Dim strFilePath As String
Dim strDocument As String
strFilePath = Trim(varLookup("Lookup", "tlkpStoredStrings", "VariableName =
'DocDir'")) 'varlookup is a replacement for DLookup.
strDocument = strFilePath & "/" & strFileName & ".DOC"
On Error GoTo Err_Exit
'HERE
Set wrd = New Word.Application
' make sure both files exist
If (Not bolFileExists(strDocument)) Then
' create new empty document
'HERE
'You first need to start up the Word application
'that's where you use the NEW keyword.
'To create a new document, use the .Add method
'of the Documents collection
Set doc = wrd.Documents.Add
doc.SaveAs FileName:=strDocument
Else
'HERE
'use the Open method for an existing file
Set doc = wrd.Documents.Open(strDocument)
End If
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
.
- Follow-Ups:
- Re: Open or Create word document from within Access
- From: richardb
- Re: Open or Create word document from within Access
- References:
- Open or Create word document from within Access
- From: richardb
- Open or Create word document from within Access
- Prev by Date: add an appointment in a specific calendar in Outlook
- Next by Date: Re: Launching Word Mail Merge from Access VBA
- Previous by thread: Open or Create word document from within Access
- Next by thread: Re: Open or Create word document from within Access
- Index(es):
Relevant Pages
|
Loading