none
How to copy tables that begins on the one page and ends on the another page? RRS feed

  • Question

  • Hello,

    I am using next code for copying contents of word document to powerpoint's slides:

      With xlWorkbook
           NumOfPages = .ActiveWindow.Panes(1).Pages.Count
           End With
    Do While i <= NumOfPages
                                  
    If i = NumOfPages Then
        With xlWorkbook
            .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(1).Range.Start, _
               End:=.Range.End).Copy
        End With
       Else
    With xlWorkbook
       .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(1).Range.Start, _
          End:=.ActiveWindow.Panes(1).Pages(i + 1).Breaks(.ActiveWindow.Panes(1).Pages(i).Breaks.Count).Range.Start).Copy
    End With
    End If
    
     On Error Resume Next
               If Err.Number = 0 Then
                   ActivePresentation.Slides.Add(Index:=numbSlide, Layout:=ppLayoutBlank).Select
                   ActiveWindow.View.PasteSpecial ppPasteOLEObject, , , , , msoTrue
                   With ActiveWindow.Selection.ShapeRange
                        .Left = 25
                        .Top = 15
                        .Width = 675
                       '.Height = 460
                       End With
                       End If             
    With xlWorkbook
    If .ActiveWindow.Panes(1).Pages(i).Breaks.Count > 1 Then
        .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(2).Range.Start, _
            End:=.ActiveWindow.Panes(1).Pages(i + 1).Breaks(2).Range.Start - 1).Copy
             On Error Resume Next
                   ActivePresentation.Slides.Add(Index:=numbSlide, Layout:=ppLayoutBlank).Select
                   ActiveWindow.View.PasteSpecial ppPasteOLEObject, , , , , msoTrue
                  With ActiveWindow.Selection.ShapeRange
                        .Left = 25
                        .Top = 40
                        .Width = 675
                       '.Height = 460                    
                   End With
                   numbSlide = numbSlide + 1
             On Error GoTo 0
             i = i + 1
             End If
            End With
             i = i + 1
          Loop

    But I can't copy whole tables if these tables begins on the one page and ends on the another page. I can only copy different parts of these tables and I don't know how to copy all my pages contents. Please see example of Word document that I don't know how to copy to PowerPoint.

    Tables.doc

    And my PowerPoint's file with macro that copying open word documents

    PowerPoint file

    So how to copy pages contents of Tables.doc document?

    Thanks in advance!

    Monday, October 8, 2012 5:27 PM

All replies

  • Could you upload the example files in another website? I tried, but couldn't download them.

    What I think: it would be easier to loop through the Tables collection of the document and copy then to the presentation. What's the purpose of looping through the pages of the document?


    Felipe Costa Gualberto - http://www.ambienteoffice.com.br

    Monday, October 8, 2012 11:50 PM
  • Hello Benzadeus,

    Thanks for reply. Please see new links for my files: Tables.doc , PowerPoint file

    The main idea of looping pages is copy each word's page to separate powrpoint's slide. And word's pages can have different content: tables, charts, textboxes. It is SQL Server Reporting Services reports that were exported to the word documents. And we need to see these reports in PowerPoint presenatations

    If it is easier to loop through the tables or charts collection of the document, can you provide example of it for my Tables.doc document?

    I can copy tables in Tables.doc document using different items in Pages().Breaks() construction:

    With xlWorkbook
    '1st parts of tabel
        .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(1).Range.Start, _
          End:=.ActiveWindow.Panes(1).Pages(i + 1).Breaks(.ActiveWindow.Panes(1).Pages(i).Breaks.Count).Range.Start - 1).Copy
    End With
    
    '2nd part of table
        .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(2).Range.Start, _
            End:=.ActiveWindow.Panes(1).Pages(i + 1).Breaks(2).Range.Start - 1).Copy
    
    '3rd part of table
        .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(4).Range.Start, _
            End:=.ActiveWindow.Panes(1).Pages(i + 1).Breaks(4).Range.Start - 1).Copy
    
    '4th part of table
                 .Range(Start:=.ActiveWindow.Panes(1).Pages(i).Breaks(7).Range.Start, _
            End:=.ActiveWindow.Panes(1).Pages(i + 1).Breaks(7).Range.Start - 1).Copy
    But it works only with this document because if I have different word document I don't know how to recognise which of pages.breaks I should copy and parts of the word document where tables are located to copy it to the same parts of the powerpoint slide.


    Thank you.
    • Edited by Andemki Tuesday, October 9, 2012 3:22 PM
    Tuesday, October 9, 2012 3:20 PM