2017-08-08 56 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