Consulting

Results 1 to 3 of 3

Thread: Export excel data to word (in table)

  1. #1

    Export excel data to word (in table)

    hi,.
    i need some help here.I have excel with several heading such as Name,address,postcode.I would like to export all the data into word (in table format) where it contain multiple table in it.I upload the screenshot of the table in word.Thanks.

  2. #2
    Here is the sample data in excel.Thanks again

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Maybe something like:
    [VBA]Sub PasteNow()
    PasteRangeToNewDoc ThisWorkbook.Path & "\Test.doc", Selection
    End Sub

    Sub PasteRangeToNewDoc(docFilename As String, pasteRange As Excel.Range)
    Dim wdApp As Object, wd As Object, hFile As Integer
    Dim rngPaste As Word.Range

    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
    Set wdApp = CreateObject("Word.Application")
    End If

    'Create an empty docFilename if one does not exist
    If Dir(docFilename) = "" Then
    hFile = FreeFile
    Open docFilename For Binary Access Read As #hFile
    Close hFile
    End If
    On Error GoTo 0

    Set wd = wdApp.Documents.Open(docFilename)

    'Put pasteRange into clipboard
    pasteRange.Copy
    Set rngPaste = wd.Content

    'Copy to docFilename
    wdApp.Visible = True
    With wd
    'Enter value of a cell to a formfield
    '.FormFields("Brand").Result = Cells(activecell.row, "B")
    'Enter a value of a cell to the body of the doc
    'wd.Selection.TypeText Text:="hi"
    rngPaste.Collapse wdCollapseEnd
    rngPaste.InsertParagraphAfter
    rngPaste.Paste
    rngPaste.Font.Name = "Arial"
    rngPaste.Font.Size = 24
    End With

    Application.CutCopyMode = False
    Set wd = Nothing
    Set wdApp = Nothing
    End Sub
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •