我正在制作一个宏,以粘贴从excel工作簿到PowerPoint的特定范围,并且我希望允许用户能够控制图像的位置和比例。我已经编写了一个代码,其中每个工作簿的幻灯片都包含14个变量,并且我试图运行一个for循环,以便其运行更快/代码更流畅。
如下所示,我的变量(从1开始)一遍又一遍地重复,直到达到14。有没有一种方法可以运行for循环,因此我可以只允许下面的这段代码而无需粘贴14次吗?
'---------- Page ----------
If Switch1 = "Yes" Then
MySlideArray = Array(Page1)
'Period-Specific SnapShot
'List of PPT Slides to Paste to
'List of Excel Ranges to Copy from
MyRangeArray = Array(Worksheets(MS1).Range(Rng1))
'Loop through Array data
For x = LBound(MySlideArray) To UBound(MySlideArray)
'Copy Excel Range
MyRangeArray(x).Copy
'Paste to PowerPoint and position
On Error Resume Next
Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 2007-2010
Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
On Error GoTo 0
'Custom sizing
With myPresentation.PageSetup
PowerPointApp.ActiveWindow.Selection.ShapeRange.LockAspectRatio = False
shp.Width = w1 * 72
shp.Height = h1 * 72
'shp.Width = 159
'shp.Height = 248
'switch for USER to allow customer positioning or default center image in ppt
If stc1 = "Yes" Then
shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
Else
shp.Left = Hz1 * 72
shp.Top = Vr1 * 72
End If
End With
Next x
End If