Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Looping thru open word documents to find a specific one

My Excel VBA code checks to see if a specific word file is open.

If I have more than one inistance of Word open, my code only "sees" on
instance.

How can I loop through all the instances of Word that are open to find the
specific document I want to act on?

================================================== ===

Private Sub cmdOpenPRRRDoc_Click()

Dim WordApp As Object
Dim fNameAndPath As String
Dim doc As Variant, x As Integer

On Error Resume Next
fNameAndPath = GetPRRRFileName


' CHECK TO DETERMINE IF THE FILE IS ALREADY OPEN
' IF NOT OPEN - THEN OPEN IT
If Not FileLocked(fNameAndPath) Then
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open (fNameAndPath)
WordApp.Visible = True
Set WordApp = Nothing
Exit Sub
End If

' IF OPEN - THEN ACTIVATE IT
For Each doc In Documents
If InStr(1, fNameAndPath, doc.Name, vbTextCompare) 0 Then
doc.Activate
End If
Next

' IF MORE THAN ONE INSTANCE OF WORD IS OPEN, I MAY MISS THE FILE IN MY
FOR-EACH LOOP

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Looping thru open word documents to find a specific one

This ain't easy and involves API programming (window handlers, etc). Here's
a couple of references to get you started:

http://www.informit.com/articles/art...&seqNum=3&rl=1
http://www.bmsltd.ie/Spreads/ProExcelDev09.pdf

"dsimcox" wrote:

My Excel VBA code checks to see if a specific word file is open.

If I have more than one inistance of Word open, my code only "sees" on
instance.

How can I loop through all the instances of Word that are open to find the
specific document I want to act on?

================================================== ===

Private Sub cmdOpenPRRRDoc_Click()

Dim WordApp As Object
Dim fNameAndPath As String
Dim doc As Variant, x As Integer

On Error Resume Next
fNameAndPath = GetPRRRFileName


' CHECK TO DETERMINE IF THE FILE IS ALREADY OPEN
' IF NOT OPEN - THEN OPEN IT
If Not FileLocked(fNameAndPath) Then
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open (fNameAndPath)
WordApp.Visible = True
Set WordApp = Nothing
Exit Sub
End If

' IF OPEN - THEN ACTIVATE IT
For Each doc In Documents
If InStr(1, fNameAndPath, doc.Name, vbTextCompare) 0 Then
doc.Activate
End If
Next

' IF MORE THAN ONE INSTANCE OF WORD IS OPEN, I MAY MISS THE FILE IN MY
FOR-EACH LOOP

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting specific data from inconsistant multiple word documents Matt Bennette[_2_] Excel Discussion (Misc queries) 4 January 5th 09 01:30 PM
Can only open Read-Only Word documents from Excel using VBA Dave.Punk.Emo Excel Programming 6 August 13th 07 04:32 AM
Possible to open word documents in Excel using hyperlinks? DobieM New Users to Excel 2 July 12th 06 04:08 PM
how do you get Word to open documents in it's own window(s)? othree7 Excel Discussion (Misc queries) 0 November 16th 05 04:21 PM
Can't open excel or word documents (says insert sm bus cd?) Angela27 Excel Discussion (Misc queries) 0 June 20th 05 07:31 PM


All times are GMT +1. The time now is 11:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"