0

我希望我能得到一些关于这段代码的帮助。我从 The Spreadsheet Guru 中找到了以下代码,用于复制一系列单元格并将它们粘贴到 PowerPoint 中的不同幻灯片上。问题是 - 范围(拼图)根据单元格“A6”的值更改,在此处输入图像描述

我想导出拼图,即 Range("M1:U11"),但我希望从 No 1 到 300 的每个拼图都出现在 Powerpoint 演示文稿的单独幻灯片上。因此,当 A6 = 1 时,导出 1 号拼图,当 A = 2 时,导出 2 号拼图,依此类推。

Private Sub CommandButton1_Click()

 'Declare our Variables
    Dim r As Range
    Dim powerpointapp As Object
    Dim mypresentation As Object
    Dim myslide As Object
    Dim myshape As Object
    
    
    'assigning range into variable
    Set r = ThisWorkbook.Worksheets("Sheet1").Range("M1:U11")
    
    'If we have already opened powerpoint
    Set powerpointapp = GetObject(class:="PowerPoint.Application")
                      
    'If powerpoint is not opened
    If powerpointapp Is Nothing Then Set powerpointapp = CreateObject(class:="PowerPoint.Application")
    
    'To create a new presentation
    Set mypresentation = powerpointapp.Presentations.Add
    
     
     'I tried creating a For Loop through all the values in "A6" but got stuck
    
    Set myslide = mypresentation.slides.Add(1, 11)
    
    r.Copy
    
    'to paste range
    myslide.Shapes.PasteSpecial DataType:=2
    Set myshape = myslide.Shapes(myslide.Shapes.Count)
    myshape.Left = 250
    myshape.Top = 150
    
    powerpointapp.Visible = True
    powerpointapp.Activate
    
    'to clear the cutcopymode from clipboard
    Application.CutCopyMode = False
    
    
    'Keep going if there is an error
    On Error Resume Next

End Sub
4

0 回答 0