2014-10-09 163 views
0

我已經寫了一個vba腳本,基本上將一張表插入到帶有文本「單元格中的示例文本」的幻燈片中,現在我想將圖像添加到單元格中該表取決於文件夾中表格的大小。使用宏將圖像插入表格(vba powerpoint 2010)

基本上,如果它是5X3表,那麼它應該從該文件夾中取出15張圖像,並將其排列到帶有圖像文件名的單元格中。這是我想要的輸出是這樣的:

enter image description here

這是我寫的代碼是:

Sub NativeTable() 
    Dim pptSlide As Slide 
    Dim pptShape As Shape  ' code to create table in present slide 
    Dim pptPres As presentation 
    Dim iRow As Integer 
    Dim iColumn As Integer 
    Dim oShapeInsideTable As Shape 

    Set pptPres = ActivePresentation 
    With pptPres 
     Set pptSlide = .Slides.Add(.Slides.Count, ppLayoutBlank) 
    End With 
    With pptSlide.Shapes 
     Set pptShape = .AddTable(NumRows:=3, NumColumns:=5, Left:=30, _ 
           Top:=110, Width:=660, Height:=320) 
    End With 
    With pptShape.Table 
     For iRow = 1 To .Rows.Count 
      For iColumn = 1 To .Columns.Count 
       With .Cell(iRow, iColumn).Shape.TextFrame.TextRange 
        .Text = "Sample text in Cell" 
        With .Font 
         .Name = "Verdana" 
         .Size = "14" 
        End With 
       End With 
      Next iColumn 
     Next iRow 
    End With 
End Sub 

所以,我怎麼能做到這一點,請幫助我這個和圖像應可調整大小(如這是可能的)請幫我這 這是可能的我檢查了msdn對象的引用,但沒有選擇在單元格中插入圖片

回答

0

作爲單元格背景插入。選擇一個單元格>設計>底紋>圖片

0

我對派對有點遲到,但這裏是代碼,以防其他人需要它。只要確保在括號中更改變量以適合您的需求。

PowerPoint.ActivePresentation.Slides(1).Shapes("table_1").Table.Cell(1, 2).Shape.Fill.UserPicture ("location_of_picture_file")