Microsoft Word 8.0 object model Question #1

On a form, I have a command button with the following code inserted on the Click event:

Private Sub Command1_Click()

Dim wordapp As New Word.Application

wordapp.Visible = True

Set wordapp = Nothing

End Sub

When you click the button for the first time, it opens up Microsoft Word. However, if you do not close Word and click the button again, you get a VB runtime error (Automation error). What you really want to happen is another instance of Word to open up.

It seems the problem is to do with trying to start another Winword.exe process, but I can't work out how to solve it.

That's the question, I hope someone can help.


S Williams.
Who is Participating?
MirkwoodConnect With a Mentor Commented:
problems on:
              Word 95        Word 98       Word 2000
- Win95          No              No             No
- WinNT          No              No             No
- Win98          No              No             No
- Win2000        No              No             No

Spooky, I tried the same but had no problem.
Are you working on an operating system or are you using Windows 95?
What about this for a test:

Option Explicit
Dim objWApp As Word.Application

Private Sub cmdExit_Click()

If objWApp Is Nothing Then
    'no need to do anything
    Exit Sub
End If

Dim objX As Word.Document

For Each objX In objWApp.Documents
    objX.Close False
    'False = close it without prompting for changes

objWApp.Quit False
'False = If anything's still open you won't be prompted for save.

Set objWApp = Nothing

End Sub

Private Sub cmdNew_Click()

If objWApp Is Nothing Then
    Set objWApp = New Word.Application
End If

'Add a new document
If objWApp.Visible = False Then
    objWApp.Visible = True
End If


End Sub

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Mirkwood - surely TheNugget is not imagining the problem?
Yep he is..
TheNuggetAuthor Commented:
I've got a feeling it's some problem with the way Microsoft Office is set up on my system.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.