for each doc in dir, copy data to excel

M

Max Bialystock

Hello there,

I have a directory full of word docs.

Each doc contains just name and address.

Each doc was used to print an address label for a parcel.

I need to get the name and address from each file, together with the date
the file was created.

This will provide a record in Excel of when each parcel was prepared for
dispatch.

I'm 99% sure this can be done with an Excel VBA routine, but I don't have
the skill to write it myself.

If anyone can help, Ill be most grateful indeed.

Max
 
N

NickHK

Max,
In psuedo-code, something like:
'Make a reference to the Word type library
'in VBE>Tools>references

Dim Filename As String
Dim FileCount As Long
Dim WordApp As word.Application
Dim WordDoc As word.document

filename=dir(<path to the folder> & "\*.doc")
Set WordApp = New word.Application

With Worksheets("data").Range("a1")
Do While Filename <> ""
FileCount = FileCount + 1
set worddoc=wordapp.documents.open(<path to the folder> & "\" &
filename)

.offset(filecount,0)=worddoc.<name data>
.offset(filecount,1)=worddoc.<address data>
.offset(filecount,2)=filedatetime(<path to the folder> & "\" &
filename)

WordDoc.Close
Loop
End With

WordApp.Quit

You can record a macro in Word to see the syntax of getting the name and
address data.

NickHK
 

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