none
Possible problem involving Word application calls from VB.net RRS feed

  • Question

  • As I've mentioned elsewhere I've recently switched jobs.  In my old job I spent years making calls to MS Project 2003 from VB.Net (Visual Studio 2005).  In my new job I call Word (CreateObject("Word.Application"), etc.) using Visual Studio 2008

    I seem to be getting this popup intermittently reading "Reentrancy was detected" when I step through the code and make the CreateObject call.  (And it doesn't seem to be doing it this morning so I can't look at the included help.)  I probably don't understand what I'm seeing on line so far.  Are they saying that Word itself is trying to call managed code, i.e. my program?  In any case it doesn't seem to be an actual crash.  I seem to be able to continue normally.

    Suggestions?

    Friday, June 24, 2011 1:02 PM

Answers

  • Hi Chernik

    CreateObject is older, I wouldn't use the term "obsolete" as there may be circumstances where it makes sense. The "new" keyword was introduced at a later point, but is definitely useable with any VBA-capable version of Word (back to version 97). I believe CreateObject was necessary with the WordBasic versions of Word. So using "new" should affect any interaction with an older version adversly.

    People may use CreateObject as it "pairs" with GetObject (GetActiveObject in the .NET Framework); IOW they may feel more "comfortable" using two things that are "alike". Or, they may simply have found the one and not realized the other possibility existed.

    I don't know all the details about the difference in how CreateObject and New work. I do know that CreateObject works with a different set of Windows APIs (in the .NET Framework Activator.CreateInstance, see also http://blogs.msdn.com/b/andreww/archive/2008/11/30/starting-or-connecting-to-office-apps.aspx), which calls the exe by file name. The New keyword looks up the designation in the Registry and from that entry looks up the path to the file exe.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 28, 2011 6:50 AM
    Moderator

All replies

  • I've never encountered the message you mention, but then I never use CreateObject in .NET. I always use the New keyword when instantiating an Office application:

    Dim myWordApp as Word.Application = new Word.Application()

    for example. Is there any reason you don't do that?


    Cindy Meister, VSTO/Word MVP
    Friday, June 24, 2011 3:42 PM
    Moderator
  • You're right.  I've checked my old work and that's what I did in my old job. 

    I have absolutely no clue why this app is using CreateObject.  Is it obsolete?


    (Perhaps I should ask, what is the fundamental difference between CreateObject and New Word object?)

    (On second thought, perhaps a more important question would be: If this is a legacy call, what effect if any will substituting New Application objects calls have on systems with older versions of Office?  Right now I'm running VS2008 and Office 2010.  I'm told that some of our clients may be running systems as old as Office 2000, maybe.)

    Monday, June 27, 2011 3:07 PM
  • Hi Chernik

    CreateObject is older, I wouldn't use the term "obsolete" as there may be circumstances where it makes sense. The "new" keyword was introduced at a later point, but is definitely useable with any VBA-capable version of Word (back to version 97). I believe CreateObject was necessary with the WordBasic versions of Word. So using "new" should affect any interaction with an older version adversly.

    People may use CreateObject as it "pairs" with GetObject (GetActiveObject in the .NET Framework); IOW they may feel more "comfortable" using two things that are "alike". Or, they may simply have found the one and not realized the other possibility existed.

    I don't know all the details about the difference in how CreateObject and New work. I do know that CreateObject works with a different set of Windows APIs (in the .NET Framework Activator.CreateInstance, see also http://blogs.msdn.com/b/andreww/archive/2008/11/30/starting-or-connecting-to-office-apps.aspx), which calls the exe by file name. The New keyword looks up the designation in the Registry and from that entry looks up the path to the file exe.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 28, 2011 6:50 AM
    Moderator
  • Hi Cindy,

     

    Thanks for your help on this issue. I think the main different between “New” and “CreateObject” is early binding and late binding, which is just like what they talked about in this similar thread:

    http://www.vbforums.com/showthread.php?t=349396

    New is used for early binding, and it might be faster than CreateObject (late binding) in some situation.

     

    “Depend on different situations, which form of binding should be use” is explained in this KB article: http://support.microsoft.com/kb/245115

     

    Hi Chernik,

     

    Have a look at Cindy reply and above article, if you have you further concern, please feel free to me know.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 4, 2011 6:03 AM
    Moderator