Access VBA Calling MSWord/Excel VBA? 
Author Message
 Access VBA Calling MSWord/Excel VBA?

I have created a monster.  I have a set of 200-300 MS Word documents that
have information in tables.  I want to pick information off of each document
and ultimately store them in an Access database for analysis.

After realizing that I couldn't hand key this info in every week (it'd be a
problem figuring out which documents had changes, then keying the changes),
I wrote a VBA routine to look in certain folders, search for all documents
in the subfolders then pick up the info I wanted from each document then
paste the info into a consolidated list in a new word document.

I want to then copy the word table to excel (since Access can't read word
files).  Then I can import the data from Excel to Access.

So...my question is, can I create a form and VBA program in Access to call
MS word, invoke my Word VBA routine to create the data, then somehow
automate the copy from MS Word, and Paste into Excel.  Then, save the Excel
File and do the import into Access?   Right now, I have three manual pieces:
1.  Open word, run word VBA routine
2.  Open Excel, do manual copy paste from Word, save
3.  Open Access, VBA to import Excel file

This is workable, but I'd love to have one button that would do all three
processes automatically for me!   Any ideas? I'm doing this at work and I'm
using version 97 of word, excel and access and do not have Visual Basic
(which I suspect could "pull" this all together!).



Thu, 01 Sep 2005 02:12:40 GMT  
 Access VBA Calling MSWord/Excel VBA?
Lets clear up a few things, and then lets look towards a solution:

Quote:
>> using version 97 of word, excel and access and do not have Visual Basic
> (which I suspect could "pull" this all together!).

Excel, Word, and ms-access all have VBA. Not sure why you think Excel does
not have VBA. (just try hitting alt-f11 while in word, or excel..you will
see the full VBA environment in both of the products). Ms-access also have
VBA, but does not have VB forms like Excel, and word does.

Regardless, you can probably run the whole process from ms-access, and skip
Excel all together. (so, yes, you can call/run the word code form
ms-access). In fact, I would use the code you have for word now, and move it
into ms-access. It could process all the documents, and grab the data. This
will work *if* the word results are in a reasonable table format. If the
data is NOT structured, and you have to massage the data in Excel, then this
may not work. It really depends on how nice the data from word is. If you
have to do a lot of manual re-formatting in Excel, then things get
difficult.

Quote:
> 1.  Open word, run word VBA routine
> 2.  Open Excel, do manual copy paste from Word, save
> 3.  Open Access, VBA to import Excel file

If the data in word is in a table, then  you can in ms-access open that word
doc, and take data from the table:

The code can look like:

   Dim MyWord As Word.Document
   Set MyWord = GetObject(strWordDoc)

   ' move to the table in word doc
   MyWord.GoTo wdGoToTable, wdGoToFirst, 1

   ' now get the next 9 entries from the table and
   ' stuff them into our array

   For i = 1 To 9

      MyWord.ActiveWindow.Selection.MoveRight wdCell, 2
      'colHold.Add MyWord.ActiveWindow.Selection, CStr(i)
      mybuf(i) = MyWord.ActiveWindow.Selection

   Next i

   MyWord.ActiveWindow.Close wdDoNotSaveChanges

   Set MyWord = Nothing

   ' at this point our string array has 9 values in it..

The above would need more work to grab the "next" line of the table data,
but it certainly can be done. Thus, you can get ms-access to open the word
docs, and grab all the data
Here is for example some code in ms-access that opens a word doc, reads the
table data from word right into a table in ms-access.

--
Albert D. Kallal
Edmonton,  Alberta Canada

http://www.attcanada.net/~kallal.msn



Thu, 01 Sep 2005 03:29:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VBA coding to call an Excel VBA macro from Outlook

2. Call Excel VBA from Word VBA?

3. VBA Analysis Tookpack- Excel In Access VBA

4. vba access vs vba excel (alguien sabe?)

5. Windows EXCEL VBA / MAC EXCEL VBA compatibility issues

6. Excel 97 VBA vs Excel 2000 VBA

7. Running excel add-in (added into excel - not access) in Access VBA

8. WSH calls VBA or VBA calls WSH

9. Access 97 VBA v Access 2K VBA - different ?

10. Access 2000 VBA Handbook vis a vis Access 97 VBA Handbook

11. Word VBA vs Excel VBA

12. NEW VBA'er(Excel) looking for other VBA'ers

 

 
Powered by phpBB® Forum Software