Solved

Dim AppWord As New Word.Application hangs

Posted on 2010-11-25
10
917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 70

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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34218713
When this code hangs, is there a Word instance running already?
0
 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

732 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