I
IanKR
I'm running Windows XP, Excel 2003 and Word 2003.
I have written two sets of code - one to be run from Excel, stored in
modules in an Excel workbook, and another that is stored in modules in a
Word document. Each set basically does the same thing:
- prompts the user for a folder on a network share;
- searches that folder (and its sub-folders, if specified) for Excel
workbooks / Word docs (as appropriate);
- opens each file in sequence (only if a password is not required to open);
- checks headers and footers (for each worksheet and chart sheet in Excel;
for each section in Word) for existing text;
- edits existing header/footer text or adds header/footer where none exists
as appropriate, and under certain circumstances;
- saves and closes the workbook / document, if changed;
- adds a hyperlinked filename and path for each file checked to a listing in
a worksheet in the Excel code workbook (for the Excel files) / on the page
in the Word code document (for the Word files) with a comment as to whether
the file was changed;
- moves onto the next file;
- at the end, each set of code shows a summary message box with the total
files checked etc.
Each set of code runs fine from within Excel / Word, but ideally what I'd
like to do is to run one set of code from Excel, and have this check all
Excel and Word files in the specified location, do the editing as necessary,
and provide a full list on the Excel worksheet. This will mean running the
Word VBA code that manipulates the Word documents from within Excel. I know
that this is possible using early binding (preferable - I've seen an example
here http://word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm ).
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?
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?
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?)
Grateful for any other general advice. I've not posted any code, but I could
do this if it helps. As I say, each set runs perfectly well in its own app,
checking for its own type of file, I'd just rather push it all into Excel.
In both cases I'm using Application.Filesearch to search for the files to
process. As I see it, there would be one instance of Application.Filesearch
and this would then branch to the Excel code to process the Excel files, or
to the Word code for the Word files, but for there to just the one
list/report for all the files, and for this to be on an Excel worksheet.
Many thanks in advance.
Ian
I have written two sets of code - one to be run from Excel, stored in
modules in an Excel workbook, and another that is stored in modules in a
Word document. Each set basically does the same thing:
- prompts the user for a folder on a network share;
- searches that folder (and its sub-folders, if specified) for Excel
workbooks / Word docs (as appropriate);
- opens each file in sequence (only if a password is not required to open);
- checks headers and footers (for each worksheet and chart sheet in Excel;
for each section in Word) for existing text;
- edits existing header/footer text or adds header/footer where none exists
as appropriate, and under certain circumstances;
- saves and closes the workbook / document, if changed;
- adds a hyperlinked filename and path for each file checked to a listing in
a worksheet in the Excel code workbook (for the Excel files) / on the page
in the Word code document (for the Word files) with a comment as to whether
the file was changed;
- moves onto the next file;
- at the end, each set of code shows a summary message box with the total
files checked etc.
Each set of code runs fine from within Excel / Word, but ideally what I'd
like to do is to run one set of code from Excel, and have this check all
Excel and Word files in the specified location, do the editing as necessary,
and provide a full list on the Excel worksheet. This will mean running the
Word VBA code that manipulates the Word documents from within Excel. I know
that this is possible using early binding (preferable - I've seen an example
here http://word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm ).
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?
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?
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?)
Grateful for any other general advice. I've not posted any code, but I could
do this if it helps. As I say, each set runs perfectly well in its own app,
checking for its own type of file, I'd just rather push it all into Excel.
In both cases I'm using Application.Filesearch to search for the files to
process. As I see it, there would be one instance of Application.Filesearch
and this would then branch to the Excel code to process the Excel files, or
to the Word code for the Word files, but for there to just the one
list/report for all the files, and for this to be on an Excel worksheet.
Many thanks in advance.
Ian