Pages

Monday, August 22, 2011

Copy a word document to excel using VBA

Macro to copy content of Word Document and paste it in Excel


Sub import_word_document()
    Dim objWord As Object
    Dim objdoc As Object
    Dim i As Integer
    Dim wkb As Workbook
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objdoc = objWord.Documents.Open("C:\Users\ADMIN\Desktop\sample files\a.docx") 'open document
    objWord.Selection.wholestory 'select content
    objWord.Selection.Copy ' copy content
    
    ThisWorkbook.Sheets(1).Select
    Range("a2").Select
    ActiveSheet.Paste 'paste content
       
    
    objdoc.Close
    objWord.Quit
    Set objdoc = Nothing
    Set objWord = Nothing

End Sub

No comments:

Post a Comment