2017-08-08 59 views
1

我的代碼如下。基本上每個PowerPoint演示表只能容納32行值得Excel數據(與標題行),所以我想滑數,增加每32行和Excel通過數據跨行到複製週期。如果這樣做沒有意義,我會很樂意嘗試和進一步解釋,但是想要給我的問題提供某種形式的背景。循環,不這樣做,即使我有一個做

至於我可以看到我有一個做,直到,循環,如果和結束,如果。但我得到了'沒有做'的錯誤,並且我爲什麼不知所措。

N = 2

Do Until n = lrow 

Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table 3") 

    With oPPTShape.Table 
      If n Mod 33 <> 0 Then 

        .Cell(n, 1).Shape.TextFrame.TextRange.Text = Cells(n + 3, 1).Text 
        .Cell(n, 2).Shape.TextFrame.TextRange.Text = Cells(n + 3, 2).Text 
        .Cell(n, 3).Shape.TextFrame.TextRange.Text = Cells(n + 3, 3).Text 
        .Cell(n, 4).Shape.TextFrame.TextRange.Text = Cells(n + 3, 4).Text 
        .Cell(n, 5).Shape.TextFrame.TextRange.Text = Cells(n + 3, 5).Text 

       n = n + 1 
      Else 
      SlideNum = SlideNum + 1 
        .Cell(n, 1).Shape.TextFrame.TextRange.Text = Cells(n + 3, 1).Text 
        .Cell(n, 2).Shape.TextFrame.TextRange.Text = Cells(n + 3, 2).Text 
        .Cell(n, 3).Shape.TextFrame.TextRange.Text = Cells(n + 3, 3).Text 
        .Cell(n, 4).Shape.TextFrame.TextRange.Text = Cells(n + 3, 4).Text 
        .Cell(n, 5).Shape.TextFrame.TextRange.Text = Cells(n + 3, 5).Text 
       n = n + 1 
      End If 

Loop 

非常感謝!

+0

對不起,修改後,用excel vba自動創建一個power point的演示文稿。 – Dave

+1

您錯過了'End With'。 – SJR

+0

不能相信我錯過了會嘗試!謝謝,如果不是專注於結束,而是忙於結束! – Dave

回答

0

仍不能確定你的數據設置和如何幻燈片看,但如果形狀被命名爲表3每張幻燈片,並有在你的表#33個總行,(標題+ 32行)和數據開始在Excel表格第5行,那麼這可能工作。您的Excel工作表的單元格引用可能需要更精確一些,如工作表(「Sheet1」)。單元格(n + 3,1).text 這裏有一些未經測試的代碼可以幫助您完成工作。

N= 2 
Do Until n = lrow 
    Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table 3") 
    With oPPTShape.Table 
     if n < 34 then 'this is because for the first slide n< 34 there is no 0 or 1 for n mod 33 
      If n Mod 33 <> 0 Then 
        .Cell(n, 1).Shape.TextFrame.TextRange.Text = Cells(n + 3, 1).Text 
        .Cell(n, 2).Shape.TextFrame.TextRange.Text = Cells(n + 3, 2).Text 
        .Cell(n, 3).Shape.TextFrame.TextRange.Text = Cells(n + 3, 3).Text 
        .Cell(n, 4).Shape.TextFrame.TextRange.Text = Cells(n + 3, 4).Text 
        .Cell(n, 5).Shape.TextFrame.TextRange.Text = Cells(n + 3, 5).Text 
       n = n + 1 
      Else ' for when n = 33 
        .Cell(n, 1).Shape.TextFrame.TextRange.Text = Cells(n + 3, 1).Text 
        .Cell(n, 2).Shape.TextFrame.TextRange.Text = Cells(n + 3, 2).Text 
        .Cell(n, 3).Shape.TextFrame.TextRange.Text = Cells(n + 3, 3).Text 
        .Cell(n, 4).Shape.TextFrame.TextRange.Text = Cells(n + 3, 4).Text 
        .Cell(n, 5).Shape.TextFrame.TextRange.Text = Cells(n + 3, 5).Text 
       n = n + 1 
      End If 
      SlideNum = SlideNum + 1 
    Else  ' when n > 33 
    x = n mod 33 
      If n Mod 33 <> 0 Then 

        .Cell(x + 1, 1).Shape.TextFrame.TextRange.Text = Cells(n + 3, 1).Text 
        .Cell(x + 1, , 2).Shape.TextFrame.TextRange.Text = Cells(n + 3, 2).Text 
        .Cell(x + 1, , 3).Shape.TextFrame.TextRange.Text = Cells(n + 3, 3).Text 
        .Cell(x + 1, , 4).Shape.TextFrame.TextRange.Text = Cells(n + 3, 4).Text 
        .Cell(x + 1, , 5).Shape.TextFrame.TextRange.Text = Cells(n + 3, 5).Text 

       n = n + 1 
      Else ' for when n = 66 or 99, etc.... start of next slide 
       SlideNum = SlideNum + 1 
        .Cell(x + 1, 1).Shape.TextFrame.TextRange.Text = Cells(n + 3, 1).Text 
        .Cell(x + 1, , 2).Shape.TextFrame.TextRange.Text = Cells(n + 3, 2).Text 
        .Cell(x + 1, , 3).Shape.TextFrame.TextRange.Text = Cells(n + 3, 3).Text 
        .Cell(x + 1, , 4).Shape.TextFrame.TextRange.Text = Cells(n + 3, 4).Text 
        .Cell(x + 1, , 5).Shape.TextFrame.TextRange.Text = Cells(n + 3, 5).Text 
      End If 
    End If ' for checking n<34 
End With 
Loop