• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1052
  • Last Modified:

Dim AppWord As New Word.Application hangs

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
SETP
Asked:
SETP
  • 4
  • 2
  • 2
  • +1
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
If you can afford it, Aspose it better then Automation: http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
0
 
SETPAuthor Commented:
Thanks for your reply emoreau. Unfortunately we have an almost non-exsistant budget, so were forced to use Microsoft Office...
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Personally I don't know but try late binding:

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

Chris
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
CodeCruiserCommented:
When this code hangs, is there a Word instance running already?
0
 
SETPAuthor Commented:
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
 
CodeCruiserCommented:
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
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Did late binding help or change the symptoms?

Chris
0
 
SETPAuthor Commented:
Ok i've been testing it this whole week and I think your suggestion worked... Thanks
0
 
SETPAuthor Commented:
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
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.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now