How to open & copy paste a word document in excel using macros?

A

Amit Raokhande

Dear Friends,

I wanted to create an excel macro which will do the following:
-Ask for a path to open a word document
-Copy and paste data from word (which is in table format) to excel

Could you please assist me?
If possible please also mail me your answers at (e-mail address removed)
Thanks in advance for your help!!!
 
J

Jacob Skaria

Hi Amit

Try the below which copies the 1st table from the word document to excel
active sheet range A1

Sub Macro2()

Dim strFile As String, wrdApp As Object, wrdDoc As Object

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Filters.Add "Word Documents", "*.doc", 1
.InitialFileName = "C:\"
.Show
strFile = .SelectedItems(1)
End With

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
Set wrdDoc = wrdApp.Documents.Open(strFile, ReadOnly:=True)

wrdDoc.Tables(1).Range.Copy
Range("A1").PasteSpecial xlPasteValues
wrdDoc.Close False

Set wrdDoc = Nothing
Set wrdApp = Nothing


End Sub
 

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