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
    ActiveSheet.Paste 'paste content
    Set objdoc = Nothing
    Set objWord = Nothing

End Sub

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...