Consulting

Results 1 to 1 of 1

Thread: Copy range from excel into a word template document

  1. #1

    Copy range from excel into a word template document

    Hi everyone,

    I was wondering if it was possible to copy a range of data from excel to word with proper pagebreaks.

    Essentially i want the code to copy maybe 2 or 3 tables from excel, copy this into word while having each table copy to its own page within word. Another thing i would like to have is perhaps create a word template file with company logos(i would do this myself, not with a macro) , and have it open the template, and copy the data to this template and save the file. I have been at this for a few days now and i cant seem to get the data to copy with pagebreaks. Right now i have a dirty method which copies and forces me to save a different document for each table, but this could be painful if i were to increase this to say 4-5 tables or more. If anyone could help I would really appreciate it. Thanks .



    [vba]Private Sub Copy_Keep_Formatting(ByVal t As Integer, ByVal p As Integer)
    Dim wApp As Object
    Dim wDoc As Object
    Dim rnValue As Range
    Dim lastrow As Long

    lastrow = Sheets(1).Cells(65536, t + 1).End(xlUp).Row

    With Sheets(1)
    Set rnValue = .Range(Cells(4, t), Cells(lastrow + 1, p))
    End With

    Set wApp = CreateObject("Word.Application")
    Set wDoc = wApp.Documents.Add
    With wDoc
    rnValue.Copy
    .Content.Paste
    Application.CutCopyMode = False
    '.SaveAs Filename:=ThisWorkbook.Path & "\file.doc"
    .Close
    End With

    wApp.Quit
    Set wDoc = Nothing
    Set wApp = Nothing

    End Sub[/vba]
    Last edited by Ken Puls; 07-03-2006 at 10:12 PM. Reason: Added VBA tags

Posting Permissions

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