Results 1 to 5 of 5

Thread: [RESOLVED] Testing for an instance of word

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Resolved [RESOLVED] Testing for an instance of word

    Am an absolute novice using access and VBA and would appreciate an example of VB code to test for an instance of word. Am using Access 11.0 with VBA 6.04.

    Many thanks in advance,

    Best regards.

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

    Re: Testing for an instance of word

    Welcome to the Forums.

    You can test for a running instance of Word by using the GetObject function.

    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS Word xx.0 Object Library
    3. Private Sub Command1_Click()
    4.     Dim oApp As Word.Application    
    5.     Set oApp = GetObject(, "Word.Application)
    6.     If TypeName(oApp) <> "Nothing" Then
    7.         'A Word instance is running
    8.     Else
    9.         'No Word instances running.
    10.     End If
    11.     '...
    12.     '...
    13. End Sub
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: Testing for an instance of word

    Many thanks for the reply.

    This is the code I have used and when run, I get a

    Run-time error '429':

    ActiveX component can't create object - at the Set oApp = GetObject (, "Word.Application") line.

    VB Code:
    1. Private Sub Image251_Click()
    2.  
    3. 'Test to see if Word is running
    4.  
    5. Dim oApp As Word.Application
    6. Dim Response
    7. Set oApp = GetObject (, "Word.Application")
    8. If TypeName(oApp) = "Nothing" Then
    9.  
    10. 'Word is not running so load it
    11.  
    12. Response = MsgBox("WORD HAS BEEN SHUT DOWN AGAIN!! - So I have loaded it for you ......", vbOKOnly)
    13. Set oApp = New Word.Application
    14. oApp.Visible = True
    15. oApp.WindowState = wdWindowStateMinimise
    16.  
    17. Else
    18.  
    19. 'Word is running
    20.  
    21. Set oaPP = Nothing
    22. Set Response = Nothing
    23. End If

    Have had a look around to see if I could solve the problem without bothering you - most suggestions seem to point to unregistered applications, missing DLL's etc.

    Office 2003 (Word) has been installed for some time and has all of the latest updates so I would be surprised if that is the issue.

    Thanks for taking the time.

    Kind regards.

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

    Re: Testing for an instance of word

    I forgot the "On Error Resume Next" statement which should go right after the "Private Sub Image251_Click()" line

    All the error is saying is that Word is not running.
    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
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: Testing for an instance of word

    Don't you guys sleep?

    That's cracked it - thanks again.

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