LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Code in Excel macro to get all open Word docs?

lstDocs was a listbox on my form in the example I gave.
D'oh!! The "lst" should have given it away. (Just because _I'm_ lax in
identifying my variables doesn't mean everyone else is!)

Got it, put it in, and it all works great! Thank you!!
Ed

"Robin Hammond" wrote in message
...
Good.

lstDocs was a listbox on my form in the example I gave.

Robin Hammond
www.enhanceddatasystems.com

"Ed" wrote in message
...
Thank you very much, Robin! This seems to be working very well.

There is one slight hitch, though. You have a variable "lstDocs" in

line
80
of the Initialize sub, but it is not Dim'ed. Is this to be a Control
(maybe
an Option Button for each vDocs?)?

Ed

"Robin Hammond" wrote in message
...
Ed,

This is a cut down version of a routine that should give you an idea.

It
looks a bit odd with the redim structure because I've cut some other
logic
out.

Public Sub EnumerateWordDocs(oWord As Object, vDocs As Variant)


'---------------------------------------------------------------------------
------------
' Procedure : EnumerateEFAWordDocs
' DateTime : 1/13/2006 16:40
' Author : Robin Hammond
' Purpose : enumerates any files that are currently open
returning
the
' results in the vDocs array


'---------------------------------------------------------------------------
------------
'
Dim vDoc As Variant
Dim lCounter As Long
Dim lVarCounter As Long

20 lCounter = 0

30 For Each vDoc In oWord.Documents

40 With vDoc

70 If lCounter 0 Then

80 ReDim Preserve vDocs(0 To lCounter)

90 Else

100 ReDim vDocs(0 To 0)

110 End If

120 vDocs(lCounter) = vDoc.FullName
130 lCounter = lCounter + 1

170 End With

180 Next vDoc

End Sub

This is in some form code to give you an idea of how to call it

Private Sub UserForm_Initialize()
Dim vDocs As Variant
Dim lCounter As Long
Dim oWord as Object

10 On Error Resume Next
20 Set oWord = GetObject(, "Word.Application")
30 On Error GoTo UserForm_Initialize_Error

40 If Not oWord Is Nothing Then

50 EnumerateWordDocs oWord, vDocs

60 If Not IsEmpty(vDocs) Then

70 For lCounter = 0 To UBound(vDocs)

80 lstDocs.AddItem vDocs(lCounter)

90 Next lCounter

110 End If

120 End If


Robin Hammond
www.enhanceddatasystems.com

"Ed" wrote in message
...
What would I use in Excel 2000 VBA to get all the currently open Word
docs?
Or, even better, break out of the code to allow the user to choose

his
doc
and select a specific position in the doc?

I have a Word macro that takes a selection copied from Excel and

pastes
it
into my Word report with certain formatting. Some of my coworkers
could
make use of this macro as well, but it would be easier to put the

macro
in
an Excel workbook I already distribute with macros than to get them

to
add
it into Word. To make it work , though, they would have to be able

to
get
it into the right Word doc from Excel - much different than having

the
doc
open and pulling it off the clipboard.

Any help is appreciated.
Ed












 
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
Word docs to Excel Eric Excel Discussion (Misc queries) 1 July 24th 07 06:28 AM
word docs to excel neil Excel Discussion (Misc queries) 1 June 18th 07 05:44 PM
Excel OLE in Word docs MLD Excel Discussion (Misc queries) 3 June 8th 05 02:13 PM
Embedding Word Docs into Excel Worksheets and Then Printing The Word Docs mr_melvis Excel Worksheet Functions 1 April 8th 05 03:00 AM
converting excel docs to word docs rolercster New Users to Excel 2 January 4th 05 07:11 PM


All times are GMT +1. The time now is 08:50 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"