Solved

Dim AppWord As New Word.Application hangs

Posted on 2010-11-25
10
873 Views
Last Modified: 2012-05-10
I am automating Microsoft Word 2007 SP2 from a Visual Basic 2010 WinForm app. I am using early binding, so I import the reference and then I run this line of code:

Dim AppWord As New Word.Application

This works 90% of the time but occassionally it hangs on that line. Any ideas why?
0
Comment
Question by:SETP
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 34212031
If you can afford it, Aspose it better then Automation: http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
0
 

Author Comment

by:SETP
ID: 34212119
Thanks for your reply emoreau. Unfortunately we have an almost non-exsistant budget, so were forced to use Microsoft Office...
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34212181
Personally I don't know but try late binding:

dim appWord as object
...
set appword = createobject("word.application")

Chris
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34218713
When this code hangs, is there a Word instance running already?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:SETP
ID: 34228500
Hi CodeCruiser, you know what, I think there is another instance of Word running. At least the last time it hung there was - I'm not sure if that's always the case. I'll keep an eye on it. Do you think that's the problem? That maybe it's not closing Word properly?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34228906
Yes that is a very common issue. You may want to try and use the existing instance and if there is no active instance then create one. You can use this code

        Dim w As Microsoft.Office.Interop.Word.Application
        Try
             w = Runtime.InteropServices.Marshal.GetActiveObject("Word.Application")
        Catch
             w = New Microsoft.Office.Interop.Word.Application
        End Try
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34228907
Did late binding help or change the symptoms?

Chris
0
 

Author Closing Comment

by:SETP
ID: 34265056
Ok i've been testing it this whole week and I think your suggestion worked... Thanks
0
 

Author Comment

by:SETP
ID: 34265062
chris_bottomley, I didn't try your suggestion because CodeCruisers suggestion seems to have worked. Yours might be a possible fix too? If I run into problems again I will defintiely give it a try. Thanks for your support.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now