Re: Open or Create word document from within Access



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 :-)

.



Relevant Pages

  • Re: Open or Create word document from within Access
    ... > Public Function OpenFile(strFileName As String) ... > Dim strFilePath As String ... > 'use the Open method for an existing file ... > Set doc = wrd.Documents.Open ...
    (microsoft.public.office.developer.automation)
  • Re: Outlook Express question
    ... IMproper string. ... Post replies to the newsgroup. ... @="Microsoft Outlook Express 6" ... >>> Jim Carlock ...
    (microsoft.public.windowsxp.general)
  • Re: Outlook Express question
    ... IMproper string. ... Post replies to the newsgroup. ... @="Microsoft Outlook Express 6" ... >>> Jim Carlock ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • RE: All FAX printers are Inaccessible
    ... Check for the string values listed on the right pane. ... This newsgroup only focuses on SBS technical issues. ... you may want to contact Microsoft CSS directly. ... I logged in as the domain admin on the client PC, ...
    (microsoft.public.windows.server.sbs)
  • Re: best design for parse
    ... before I got it accepted that the used VB.net language in ASPNET was ... of this newsgroup. ... the objective to standardize the date string to yyyy-mm-dd ... what is the best way to come up a relevant regex for the incoming ...
    (microsoft.public.dotnet.languages.vb)

Loading