 |
 |

06-30-2010, 02:27 PM
|
|
Senior Contributor
|
|
Join Date: May 2008
Posts: 805
|
|
Excel VBA GetObject(,"Word.Application")
|
If using:
Code:
Set wdApp = GetObject(, "Word.Application")
To set an object reference to an already open word app, how do you control which word app it grabs hold of? In some instances there are two processes (word apps, containers) running at the same time. This should obviously grab the first, but what if I want the second one?
|
__________________
Josh
If Google = NoHelp Then PostHere = True
|

06-30-2010, 06:34 PM
|
|
Freshman
|
|
Join Date: Sep 2005
Posts: 40
|
|
Code:
Set wdApp = GetObject("C:\FilePath\FileName.doc")
|
|

07-01-2010, 12:36 AM
|
|
Senior Contributor
|
|
Join Date: May 2008
Posts: 805
|
|
|
It seems this Word document is being created on the fly, so i dont think it has a path, unless the program (whos code i cant access) that is being used to create the word document is saving it somewhere
|
__________________
Josh
If Google = NoHelp Then PostHere = True
|

07-01-2010, 08:53 PM
|
|
Freshman
|
|
Join Date: Sep 2005
Posts: 40
|
|
Ok, if you know the document name you could use the name of the open item minus any path.. for example:
Code:
oWdApp = GetObject("Document1")
..
If you have multiple documents open and do not know what the names are, you would have to perform some type of check to verify it's the document you are looking for.. but something like this would work:
Code:
Set oWdApp = GetObject(, "Word.Application")
Do Until oWdApp.Documents.Count = 0
oWdApp.Documents(1).Close
Loop
That would iterate through the open documents and close them all. You could do something like a For Each.. depends what u are doing with them.
Hope this helps.
|
|

07-05-2010, 01:46 PM
|
|
Senior Contributor
|
|
Join Date: May 2008
Posts: 805
|
|
|
Okay that information would be helpful I think. Im not sure but I think part of the reason I was not able to get working what I needed is that the document was pw protected so as soon as i added code to unprotect it, i was able to withdraw data from the formfields. Either that or maybe i was typing something wrong =p
|
__________________
Josh
If Google = NoHelp Then PostHere = True
|

07-05-2010, 02:47 PM
|
 |
Contributor
|
|
Join Date: Jul 2009
Posts: 506
|
|
Quote:
Originally Posted by Josh Hazel
If using:
Code:
Set wdApp = GetObject(, "Word.Application")
To set an object reference to an already open word app, how do you control which word app it grabs hold of? In some instances there are two processes (word apps, containers) running at the same time. This should obviously grab the first, but what if I want the second one?
|
You don't, the system manages it.
|
|

07-05-2010, 03:30 PM
|
|
Senior Contributor
|
|
Join Date: May 2008
Posts: 805
|
|
|
That was part of our discussion. If you check processes open, it seems as though I sometimes have 2 x WinWord.exe processes running. Which means if it grabs the first instance automatically, its going to possibly grab the wrong instance. If I am incorrect please elaborate.
|
__________________
Josh
If Google = NoHelp Then PostHere = True
|

07-16-2010, 07:06 PM
|
|
Senior Contributor
|
|
Join Date: May 2008
Posts: 805
|
|
So, I sorta figured a work around since I wasnt able to specificy what instance of the Word App to get. First of all, I found out that the WinWord.exe that it was grabbing, was not even Visible meaning i could only close it through task manager.
I have yet to determine if it was my prog (bad code) causing this or another prog. Anyway, to resolve this I just:
Code:
'Set application instance
Set wdApp = GetObject(, "Word.Application")
'Check if there is an extra app process running, if is then close it
If wdApp.Visible = False Then
wdApp.Quit False
Set wdApp = Nothing
Set wdApp = GetObject(, "Word.Application")
End If
simply just quite the app thats not visible, then regrab the next app - works for me so far
|
__________________
Josh
If Google = NoHelp Then PostHere = True
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|