Results 1 to 3 of 3

Thread: Copy and Paste Page to Each Row in Excel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Contributor D_Marcel's Avatar
    Joined
    Feb 2012
    Location
    Tokyo
    Posts
    117
    Location

    Copy and Paste Page to Each Row in Excel

    Dears,

    Greetings!
    I'm facing a very tricky situation related to the MS Word, since I don't know any VBA object to this application. I'm in a system implementation project and I have to perform more than two hundred test scenarios, each one properly evidenced and documented. I have all these scenarios organized in a Worksheet and the idea is to create one page in Word to each row in Excel. Combining my skills in VBA to Excel and what I found in the forums, I got this:

    [VBA]Sub Create_Tests_Document()

    Dim LV_WordApp As Object
    Dim LV_RowsCounter As Integer
    Dim LV_RowIndex As Integer

    LV_RowsCounter = ActiveSheet.UsedRange.Rows.Count

    Set LV_WordApp = CreateObject("Word.Application")
    LV_WordApp.Visible = True
    LV_WordApp.Documents.Open "C:\Users\douglasmmm\desktop\MyFile.docx"

    For LV_RowIndex = 2 To LV_RowsCounter
    LV_WordApp.Selection.GoTo What:=wdGoToPage, Name:=LV_RowIndex - 1
    LV_WordApp.ActiveDocument.Bookmarks("\Page").Range.Copy
    LV_WordApp.Selection.GoTo What:=wdGoToPage, Name:=LV_RowIndex - 1
    LV_WordApp.Selection.Paste
    With LV_WordApp.ActiveDocument.Tables(LV_RowIndex - 1)
    .Cell(2, 1).Range.Text = Cells(LV_RowIndex, 2).Value
    .Cell(2, 2).Range.Text = Cells(LV_RowIndex, 10).Value
    End With
    Next LV_RowIndex
    End Sub[/VBA]

    But it's not working properly because, although the code is designed to copy the last page, only the first page is copied, so I
    can't update the table of the page.

    What I need is:

    1. Copy the Last Page;
    2. Paste the Copied Page after the Last Page;
    3. Edit the table of this last page with the number and the description of the scenario, according to the value of the variable LV_RowIndex in the For Each Next structure.

    Can someone please help me?

    Thanks a lot!
    Last edited by D_Marcel; 05-17-2016 at 11:54 AM. Reason: Better words
    "The only good is knowledge and the only evil is ignorance". Socrates

Posting Permissions

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