Results 1 to 10 of 10

Thread: stuck in Word automation hell

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    74

    stuck in Word automation hell

    Earlier this year, I developed a VB 6 application to automatically generate letters as Microsoft Word documents. After extensive testing and debugging, it worked flawlessly on my Win XP development machine. Now, while I'm attempting to troubleshoot a run-time error the end users are having, the same application throws this error on my machine:

    -2147417851
    Automation error
    The server threw an exception.

    when it executes the "Set WordDoc =" statement shown below. This happens regardless of whether I'm running the compiled .EXE or in the VB IDE, and regardless of whether an instance of Word is already running. The document whose name is stored in the constant BHRSLetterName exists and can be opened manually without any problem.

    Does anyone have a clue as to why this would suddenly stopped working, and how to correct it? Thanks in advance.

    [the following code is in a standard module]
    Public Const BHRSLetterName = "\\Parker\BHRSLetters\BHRS Welcome Letter.doc"

    [the following code is in a form module]
    Private Sub DoLetters(...)
    ...
    Dim WordApp As New Word.Application
    ...
    CreateLetter ..., WordApp, ...
    ...
    End Sub

    Private Sub CreateLetter(..., WordApp As Word.Application, ...)
    Dim WordDoc As Word.Document
    ...
    Set WordDoc = WordApp.Documents.Open(BHRSLetterName, , True)
    ...
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: stuck in Word automation hell

    Does anyone have a clue as to why this would suddenly stopped working
    have you changed word versions, or are some running different version?

    try changing code to late binding, this should eliminate the main versioning problem, some others may still exist, depending on your code
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    74

    Re: stuck in Word automation hell

    No change in Word version - everyone's been running Office 2007 since before this application was written.

    Specifically what would I need to do to change to late binding?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: stuck in Word automation hell

    Check out this faq on automating word with vb6

    http://www.vbforums.com/showthread.p...App-using-VB-6
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    74

    Re: stuck in Word automation hell

    Since my original posting, I've tried using late binding (changing both WordApp and WordDoc to type Object), using a local Word document that I just created (and clearly have rights to) which has no spaces in the file spec, Word.Application.12 instead of Word.Application (that won't compile), and putting a three second delay into DoLetters() before it calls CreateLetter(). All of this is to no avail - it still chokes on the same statement with the same error, despite the fact that it runs fine on everyone else's machine, and previously ran fine on mine.

    Any other ideas?

  6. #6
    Addicted Member 3com's Avatar
    Join Date
    Jul 2013
    Location
    Spain
    Posts
    253

    Re: stuck in Word automation hell

    Word.Application.12 instead of Word.Application (that won't compile)
    ¿Did you tried something such as...

    Set oWord = CreateObject("Word.Application.12")

    after that?

  7. #7
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: stuck in Word automation hell

    Hi

    it could be some bad project references, try creating a new project and testing the code there..
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: stuck in Word automation hell

    have you tried reinstalling word?

    can you open the document using VBA code from within word?

    your code shows dimensioning of wordapp, but not setting it, i assume that line was just snipped, not accidentally cut out?

    trying a new project is a good idea, but with latebinding, no references required
    can you try using getobject directly on the document?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: stuck in Word automation hell

    I do not think this has anything to do with early/late binding. I think it is just an office installation issue. I've run into similar problems before where I work and a repair install usually does the trick.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: stuck in Word automation hell

    If it wont compile with "Word.Application" under your system or the problematic computer? It should compile/run and if not then there is a problem with word.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width