Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA:将Excel范围粘贴为Powerpoint中的表格_Vba_Excel_Powerpoint - Fatal编程技术网

Excel VBA:将Excel范围粘贴为Powerpoint中的表格

Excel VBA:将Excel范围粘贴为Powerpoint中的表格,vba,excel,powerpoint,Vba,Excel,Powerpoint,我正在尝试自动创建每月都要制作的powerpoint幻灯片。我在Excel VBA中工作,不知道如何从Excel复制范围,并将其粘贴到幻灯片中作为表格 以下是我目前掌握的代码: Sub Open_PowerPoint_Presentation() Dim objPPT As Object, _ PPTPrez As PowerPoint.Presentation, _ pSlide As PowerPoint.Slide Set objPPT = CreateObject("PowerPoi

我正在尝试自动创建每月都要制作的powerpoint幻灯片。我在Excel VBA中工作,不知道如何从Excel复制范围,并将其粘贴到幻灯片中作为表格

以下是我目前掌握的代码:

Sub Open_PowerPoint_Presentation()

Dim objPPT As Object, _
PPTPrez As PowerPoint.Presentation, _
pSlide As PowerPoint.Slide

Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True

Set PPTPrez = objPPT.Presentations.Open("file location")

Set pSlide = PPTPrez.Slides(4)

Dim RevenueDetail As Range
Dim RevenueDetailTable As Object

Sheets("Revenue By Type Slide").Activate

Set RevenueDetail = Range("B4:I18")
RevenueDetail.Copy

Set RevenueDetailTable = pSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile)

With RevenueDetailTable

.Left = 43.99961
.Top = 88.61086
.Width = 471.2827
.Height = 395.2163

End With

End Sub
这可以正常工作,但它将excel范围粘贴为不理想的图片。我想将它粘贴为一个表,这是默认的粘贴选项所做的,但是我失去了通过当前使用的方法在幻灯片上重新调整大小和位置的能力。我把这件事搞砸了有一段时间了,似乎弄不好

如果我修改

Set RevenueDetailTable = pSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile)
并将其更改为

Set RevenueDetailTable = pSlide.Shapes.Paste

它以我想要的格式粘贴,但我不知道如何重新定位和调整大小。任何帮助都将不胜感激。

修复了它。。。只需添加一行“pSlide.Select”即可在粘贴之前选择要粘贴到的幻灯片,并将.PasteSpecial(ppPasteEnhancedMetafile)更改为just.Paste…感谢所有帮助

Sub Open_PowerPoint_Presentation()

Dim objPPT As Object, _
PPTPrez As PowerPoint.Presentation, _
pSlide As PowerPoint.Slide

Dim RevenueDetail As Range
Dim RevenueDetailTable As Object

Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True

Set PPTPrez = objPPT.Presentations.Open("file location")

Set pSlide = PPTPrez.Slides(4)

Set RevenueDetail = Sheets("Revenue By Type Slide").Range("B4:I18")
RevenueDetail.Copy

pSlide.Select 'needed to add this line
Set RevenueDetailTable = pSlide.Shapes.Paste

With RevenueDetailTable

.Left = 43.99961
.Top = 88.61086
.Width = 471.2827
.Height = 395.2163

End With

End Sub

在下面的网站中,当我将
mySlide.Shapes.Paste特殊数据类型:=2
更改为
mySlide.Shapes.Paste
时,我得到的正是您想要的。当你现在摆弄
.Top
Left
Width
时,你会得到你所需要的。祝实现顺利:)@JvdV这是我已经尝试过的。当我将PasteSpecial(ppPasteEnhancedMetafile)更改为仅粘贴时,它将粘贴为表。但是,我不知道如何重新定位和调整大小。使用带有“.Top=88”等的With语句不再有效。我在做了一些小更改后尝试了您的代码,使其与示例PowerPoint演示文稿一起运行(并省略了工作表激活),并得出结论,我已经将其放入了答案中。这不应该是必需的,因为您已经设置了
pSlide=PPTPrez.Slides(4)
。但是,如果这对您有效,那么这就是最重要的:)。快乐的日子。@JvdV我就是这么想的,所以我从未考虑过添加它。非常奇怪,但它现在起作用了谢天谢地。。。几个小时以来,我一直在为这件事挠头,很难过…@有时是在细节中:)。然而,我仍然认为这是不必要的。复制了您的代码,添加了一些小的内容以使其在本地运行,并且它完全按照您的要求运行,而无需选择幻灯片。我总是学会远离
。选择