|
-
Apr 23rd, 2006, 04:56 PM
#1
Thread Starter
New Member
[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.
-
Apr 23rd, 2006, 07:22 PM
#2
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:
Option Explicit
'Add a reference to MS Word xx.0 Object Library
Private Sub Command1_Click()
Dim oApp As Word.Application
Set oApp = GetObject(, "Word.Application)
If TypeName(oApp) <> "Nothing" Then
'A Word instance is running
Else
'No Word instances running.
End If
'...
'...
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 24th, 2006, 04:26 AM
#3
Thread Starter
New Member
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:
Private Sub Image251_Click()
'Test to see if Word is running
Dim oApp As Word.Application
Dim Response
Set oApp = GetObject (, "Word.Application")
If TypeName(oApp) = "Nothing" Then
'Word is not running so load it
Response = MsgBox("WORD HAS BEEN SHUT DOWN AGAIN!! - So I have loaded it for you ......", vbOKOnly)
Set oApp = New Word.Application
oApp.Visible = True
oApp.WindowState = wdWindowStateMinimise
Else
'Word is running
Set oaPP = Nothing
Set Response = Nothing
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.
-
Apr 24th, 2006, 04:29 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 24th, 2006, 04:53 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|