View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Running Word (and Excel) code from within Excel, to process both file types

"IanKR" wrote in message

My queries:

1. Once I've Dim'd the Word objects at the top as per:

Dim oWord As Word.Application
Dim oDoc As Word.Document

(plus any other string / Boolean etc references that I use in the Word
code), can I literally just copy the Word code into the Excel module?


a) Fully qualify all "implicit" object references back to the reference to
the Word application.
b) Best to fully declare Word object declarations, particularly "Range"
which of could easily get confused

Instead of -
Dim oDoc As Document
Set oDoc = ActiveDocument ' implicit
do -
Dim oDoc As Word.Document
Set oDoc = oWord.ActiveDocument ' qualified

2. A I am opening more than one Word doc in sequence, would it be
preferable to open a new instance of Word app for each Word doc that I
check, or close just the document each time and keep an empty Word app
running ready for the next Word doc?


If you are about to work on a new document stick with the same instance. If
not sure quit the instance, after ensuring you have released and object
references.

3. Also, I know that for early binding I need to set a reference to MS
Word 11.0 Word Object Library in Excel's VBE via Tools | References. Is
this a setting that is "saved" with the workbook containing the code (I
want to distribute it for others to use), or will each user have to set
this reference? I'd rather keep users well clear of the VBE. (If
necessary, can this setting be made via VBA?)


The reference will be saved. If there is any possibility a user with an
earlier version of Office will use your file you will either need to convert
to Late-Binding, or ensure the reference is always saved with the lowest
version of any user. Keep in mind the reference might get resaved and
changed a newer version if the file is exchanged between users.

I didn't follow what you wrote about FileSearch.

Regards,
Peter T