how do I link data from Word to excel

G

Guest

I have a very, very large worksheet in Word 2000. I also have the same sheet
in excel 2000.

How can I link the 2 so when I'm filling in info in word certain parts of it
will appear on the spreadsheet?
 
E

Ed

Hi, Dan. A couple of questions:
-- I assume this is a matter of the Word document being an "individual"
worksheet, while the Excel workbook is a "master" list? For example, the
Word doc would be a single sales order form, and the Excel file has info
from all your sales?
-- How is the Word doc set up for data entry? Is it a protected form? Do
you tab from one entry field to another? Is it a table you fill in
manually? Does it grab info from a database?
-- Are all these files on your computer, or do you have to go across a
network?

Depending on how much is in one Word doc and how many you do each day, I'm
thinking you'd be looking at a macro to either run at the Save or Close of
your doc to grab the info and write it into Excel, or to run at the end of
the day to process all your files at once. If this is in a company
environment, will your company IT protocols allow you to run macros? And if
a network is involved, can you run a macro across your network?

Ed
 
G

Guest

You are correct on the word doc being individual but the excel is acting as
an analysis sheet. The word doc is set up as a table, I tab across to each
box to fill in i.e Name, date of birth, age and so forth. I need this date to
then appear in the analysis report to save me from copy and pasting
information over all the time as most of the time I forget to and the
spreadsheet is now out of date. I do have macro but never have used it and if
this could update at the end of the day would be great.

This spreadsheet is also a shared spreadsheet with 3 other people on a
network drive so I am assuming I would have to make sure other colleguaes are
not using it when I update? Theirs not much data I need to transfer to this
spreadsheet but the basics I msut do.
 
E

Ed

Dan:

I would set this up as a macro run from Excel. Have all your Word files
with data to be copied in one folder. The macro would allow you to browse
to your folder, iterate through all files in the folder, and open each one
to read and write the data into the workbook. This will allow you to create
a folder and copy files into it - if you take a few days off, copy those
files over, too, and they'll get read. Then just delete the extra folder
and files. This way you can keep your files separate with any other filing
system you have in place.

If the macro is in the Excel workbook and your coworkers follow these
procedures, they too can update their info. Also, if you have the workbook
open, then you should have read/write authority and not have to worry about
anyone else having the file open. (I could be wrong about that - I'll need
to check it out.)

It won't run automatically - you'll have to fire it yourself. Sorry! 8>/
You say you have a macro - do you know any VBA?

Ed
 
E

Ed

Dan:

The following macro will let you browse to a folder, iterate through all the
Word documents, read selected data into an array, and then write that array
into an Excel worksheet. This is an Excel macro, and needs to go into a
module in the workbook you want to update. With Excel open, press Alt+F11,
then from the Insert menu choose Module. Copy all the code below and paste
it into that module. While you're in the VBE, you must also set references
to the Microsoft Word and Microsoft Shell Controls And Automation libraries.
From the Tools menu, select References - scroll down to and check the boxes
next to Microsoft Word [version number] Object Library and Microsoft Shell
Controls And Automation.

To run the macro, from your worksheet press Alt+F8 and select UpdateFiles.

This macro assumes the following:
-- When you run it, you have the Excel workbook that will be updated open,
with the sheet to be updated on top.
-- All the Word files you want to read in the folder end with .doc
extension.
-- The data is in the first table in each document.
-- All the data you want to read is in the same row in adjacent column
cells.
-- The data is to be written into the first empty row in Column A.
-- When I tested this, I had three Word files, each with a 1-row, 6-column
table. This is set now for an array of six data positions, and will read up
to 100 files.

Any of these can be changed - some changes may take more adjusting than
others. If you need to run this from Word, that adjustment can also be
done.

Ed

PS -Watch out for line wrap, depending on your newsgroup reader. Some long
lines of code may break where they shouldn't, giving you errors. If you
paste this in and some lines show up in red, you may have line wrap errors.
You can also go to the Debug menu and select Compile VBA Project to check
for errors before running.

''******* Begin Code **********

Option Explicit
Option Base 1

Dim fName As String ' Folder holding Word files
Dim dName As String ' Word file with data

Dim objWkb As Workbook
Dim objWks As Worksheet
Dim arData(6, 100) As String
Dim strData As String
Dim cntFile As Long
Dim x As Long, y As Long
Dim LastRow As Long

Dim appWord As New Word.Application
Dim docWord As Word.Document
Dim rngWord As Word.Range
Dim tblWord As Word.Table
'

Sub UpdateFiles()

' Set Excel objects
Set objWkb = ActiveWorkbook
Set objWks = objWkb.ActiveSheet
' Find first empty row
LastRow = objWks.Range("A65536").End(xlUp).Row

cntFile = 0

' Get folder with Word files
fName = GetFolderName("Choose a folder")
If fName = "" Then Exit Sub

' Get Word data file
With Application.FileSearch
.LookIn = fName
.Filename = "*.doc"
y = .FoundFiles.Count

Do While .Execute
cntFile = cntFile + 1
If cntFile > y Then Exit Do
dName = .FoundFiles(cntFile)
On Error GoTo CleanUp
' Set Word objects
Set docWord = appWord.Documents.Open(dName)
Set tblWord = docWord.Tables(1)
' Read table into array
For x = 1 To 6 ' assumes six columns
Set rngWord = tblWord.cell(1, x).Range
arData(cntFile, x) = Left(rngWord.Text, Len(rngWord.Text) - 2)
Next x
docWord.Close
Loop

End With

' Write array data into worksheet
For y = 1 To cntFile - 1
For x = 1 To 6
objWks.Cells(LastRow, x) = arData(y, x)
Next x
LastRow = LastRow + 1
Next y

objWkb.Save

CleanUp:
Set docWord = Nothing
appWord.Quit
Set appWord = Nothing
On Error GoTo 0

End Sub

Function GetFolderName(sCaption As String) As String
'Needs a reference to (Tools > Reference)
'Microsoft Shell Controls And Automation
Dim oShell As Shell32.Shell
Dim oFolder As Shell32.Folder
Dim oItems As Shell32.FolderItems
Dim Item As Shell32.FolderItem

On Error GoTo CleanUp

Set oShell = New Shell
Set oFolder = oShell.BrowseForFolder(0, sCaption, 0)
Set oItems = oFolder.Items
Set Item = oItems.Item

GetFolderName = Item.Path

CleanUp:
Set oShell = Nothing
Set oFolder = Nothing
Set oItems = Nothing
Set Item = Nothing

End Function

''******* End Code **********
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top