Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Object Library (VBA/Office 10,11)

    By examining earlier posts, I was able to automate the creation of a Word document from an Excel workbook. Thank you for that.

    To two of my associates, I e-mailed the Excel template, the Word template, and instructions to reference the Word 11 Object Library and install the Word template in a specific folder. For one individual, all works perfectly, but for the other, nowhere well enough. The problem: The second individual is working with Office 10--I created this thing with Office 11.

    Any solution to this dilemma?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Object Library (VBA/Office 10,11)

    You have probably used early binding, i.e. set a reference to the Microsoft Word 11.0 Object Library in Tools | References (11.0 is the internal version number of Office 2003 applications).
    This has the tremendous advantage that you can use IntelliSense and the built-in help to get information about Word objects, properties and methods.
    But while VBA silently adjusts the reference if you run the code in a newer version of Excel/Word, it will fail in an older version.

    A workaround is to convert the code to late binding. This takes several steps, and it is best done when the code has been tested thoroughly, for you won't be able to use IntelliSense and help for the Word objects etc. after the conversion.

    1) Change all declarations involving Word objects:

    Dim app As Word.Application > Dim app As Object
    Dim doc As Word.Document > Dim doc As Object

    etc. etc.

    2) Replace all symbolic Word constants with their values. As long as you still have the reference to the Word library, you can look them up in the Object Browser (press F2 to activate it).
    For example, wdPasteText (used with PasteSpecial) should be replaced with its value 2, and wdHeaderFooterPrimary (to indicate the main header/footer) should be replaced with 1.

    3) Clear the reference to the Microsoft Word 11.0 Object Library.

    4) Save the workbook with the code.

    It should now work in any version of Word (unless you used features specific to Word 2003 but that is not very likely).

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Object Library (VBA/Office 10,11)

    >This takes several steps,
    Good one; Thanks!

  4. #4
    New Lounger
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Object Library (VBA/Office 10,11)

    Thanks again for the quick, to-the-point and clear reply.

  5. #5
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Object Library (VBA/Office 10,11)

    As an addition to HansV's excellent post -

    Make sure that ALL of your references to Word objects in code are fully referenced. If they are not you may end up with a second copy of Word running which does not close down when you are done. This will break your code on the next run-through. I got bitten by this recently when automating Excel from Access. The code ran fine first time but bombed out the second time. It was due to not fully referencing something in code (it compiled just fine BTW) so VBA created a second instance of Excel (in my case) which I could only kill from Task Manager.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •