Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word document

Status
Not open for further replies.

peljo

Technical User
Mar 3, 2006
91
BG
I have a function that open a word document to write notes in it.The functions works OK but only when a doc file name Notes is available.is it possible to create this word file in case it is not existing? In my function there is line called create object but somehow it does not work.

My function is :
Public Function MyNotes()
Dim appW As Object
On Error Resume Next
Set appW = GetObject(, "Word.Application")
Dim nErr As Integer
nErr = Err
On Error GoTo 0
If nErr Then
Set appW = CreateObject("Word.Application")
End If
appW.Visible = True
appW.Documents.Open (" C:\be\Notes")
End Function
 
Hi Peljo

Just replace the line:

appW.Documents.Open (" C:\be\notes")

With

appw.documents.add

If you want it to be based on another word template then put the file path to the template after the "add". for example

appw.documents.add "C:\template.dot"

Don't forget to have word object library added as a reference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top