Solved

Dim AppWord As New Word.Application hangs

Posted on 2010-11-25
10
861 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

746 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

12 Experts available now in Live!

Get 1:1 Help Now