Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

new ord document out of VB6

new ord document out of VB6

new ord document out of VB6

I know how to make a new document in word out of my VB App.

My Problem is that my code always starts Word new, despite it is open.
How can I determine wether word is already open or not (and only then open it new) and how can I add a new document to this already open Word ?

My Code:
 Set wdApp = New Word.Application
    wdApp.Caption = "MyName"
    Set newDoc = wdApp.Documents.Add

RE: new ord document out of VB6

You can use the GetObject and CreateObject methods:

    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set wdApp = CreateObject("Word.Application")
    End If
    wdApp.Visible = True
    wdApp.WindowState = wdWindowStateMaximize
    On Error GoTo ErrHndlr

Or, you can do a New Word.Application like you have.

    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set wdApp = New Word.Application
    End If
    wdApp.Visible = True
    wdApp.WindowState = wdWindowStateMaximize
    On Error GoTo ErrHndlr

If GetObject() returns an error, Word is not running, therefore, handle the error locally.

NOTE: I have run into problems if Outlook is running on the computer. Outlook starts an instance of winword.exe that runs in the background. It does not get real happy when you mess with that instance. If this is the case, I would recommend that you just create a new instance for your program.

Hope this helps!

While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close