Button to open new document

M

meghanwh

I'd like to put a button on a form that creates a new word document
(actually I'd like to also have a button to create a new email). I've
searched for code for it, but all I can find is to open an already
existing document. Please help. Thanks!
 
A

Arvin Meyer [MVP]

I'd like to put a button on a form that creates a new word document
(actually I'd like to also have a button to create a new email). I've
searched for code for it, but all I can find is to open an already
existing document. Please help. Thanks!

Email code (make sure that you've set a reference to Outlook):

http://www.datastrat.com/Code/OutlookEmail.txt

Word code (late binding reference not needed):

Private Sub cmdWord_Click()
Dim objWord As Object

Set objWord = CreateObject("Word.Application")
With objWord
.Documents.Open ("C:\Path to your WordDoc.doc")
.Visible = True
End With
Set objWord = Nothing

End Sub
 
M

meghanwh

Email code (make sure that you've set a reference to Outlook):

http://www.datastrat.com/Code/OutlookEmail.txt

Word code (late binding reference not needed):

Private Sub cmdWord_Click()
Dim objWord As Object

Set objWord = CreateObject("Word.Application")
With objWord
    .Documents.Open ("C:\Path to your WordDoc.doc")
    .Visible = True
End With
  Set objWord = Nothing

End Sub

Thanks. But what I'm having trouble with is that there isn't a file
already created, thus no path name. How can I get it to just open a
new, blank document?
 
A

Arvin Meyer [MVP]

Instead of:

Documents.Open ("C:\Path to your WordDoc.doc")

Use:

objWord.Documents.Add ("Normal.dot")
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Email code (make sure that you've set a reference to Outlook):

http://www.datastrat.com/Code/OutlookEmail.txt

Word code (late binding reference not needed):

Private Sub cmdWord_Click()
Dim objWord As Object

Set objWord = CreateObject("Word.Application")
With objWord
.Documents.Open ("C:\Path to your WordDoc.doc")
.Visible = True
End With
Set objWord = Nothing

End Sub

Thanks. But what I'm having trouble with is that there isn't a file
already created, thus no path name. How can I get it to just open a
new, blank document?
 

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