Sunday, July 24, 2011

Copy Data from Word to Excel By VBA




Sub CopyTextFromWord()
    Dim wApp As Word.Application
    Set wApp = New Word.Application
    wApp.Visible = True
    wApp.Activate
    wApp.Documents.Open "YourFilePath\SampleWord.docx"
    wApp.Selection.WholeStory
    wApp.Selection.Copy
    Range("A1").Activate
    ActiveSheet.Paste
End Sub

5 comments:

vba said...

hi rajan

if i run this --error appears as user difined type is not difined ( Dim wApp As Word.Application)
thanks

Rajan said...

Add the reference before run this Macro :
MicroSoft Word 12.0 Object Library

Manish Kadam said...

Thanks..!
It was very useful

Anonymous said...

Wow... thank you so much...

Unknown said...

sir please help me.

this code is not working for me

it is showing error as userdefined type is not defined

and if i include this line
MicroSoft Word 12.0 Object Library

that is too showing error
expected end of statement

sir please tell me how to add reference with full code.

expecting soon...

thanks in advance