首页 > 解决方案 > 有没有办法将我的 VBA 代码中的幻灯片编号作为用户输入来操作?

问题描述

VBA新手在这里。目前正在尝试实现一些代码,将excel中的一系列单元格传输到powerpoint中给定幻灯片中表格的预先存在的行/列中。我已经使用以下代码进行了转移:

Sub ExcelRange_to_PPT_Table()

Dim ppApp                               As PowerPoint.Application
Dim ppPres                              As PowerPoint.Presentation
Dim ppTbl                               As PowerPoint.Shape
Dim ppSlide                             As PowerPoint.Slide


On Error Resume Next
Set ppApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0

If ppApp Is Nothing Then
     Set ppApp = New PowerPoint.Application
        ppApp.Visible = True
    Set ppPres = PPTApp.Presentations.Add
    Set ppSlide = PPTP.Slides.Add(1, ppLayoutBlank)
Else
    Set ppPres = ppApp.Presentations.Item(1)
End If

ppApp.ActivePresentation.Slides(1).Select


' find on Slide Number 1 which object ID is of Table type (you can change to whatever slide number you have your table)
With ppApp.ActivePresentation.Slides(1).Shapes
    For i = 1 To .Count
        If .Item(i).HasTable Then
            ShapeNum = i
        End If
    Next
End With

' assign Slide Table object
Set ppTbl = ppApp.ActivePresentation.Slides(1).Shapes(ShapeNum)

' copy range from Excel sheet
Range("A1:D5").Copy

' select the Table cell you want to copy to >> modify according to the cell you want to use as the first Cell
ppTbl.Table.Cell(1, 1).Shape.Select

' paste into existing PowerPoint table - use this line if you want to use the PowerPoint table format
ppApp.CommandBars.ExecuteMso ("PasteExcelTableDestinationTableStyle")



End Sub

我想实现某种用户 IO,允许用户在 excel 中输入他们想要传输的范围以及他们想要传输到的表格的幻灯片 # + 行/列,但是我正在努力使用将更改预设的 VBA 代码来执行此操作的用户 io。有什么建议么?谢谢!

标签: excelvbapowerpoint

解决方案


推荐阅读