Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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
使用VBA将MS Excel中的单元格区域粘贴到MS PowerPoint中_Vba_Excel_Powerpoint - Fatal编程技术网

使用VBA将MS Excel中的单元格区域粘贴到MS PowerPoint中

使用VBA将MS Excel中的单元格区域粘贴到MS PowerPoint中,vba,excel,powerpoint,Vba,Excel,Powerpoint,我使用下面的代码将Excel中的单元格区域作为图像粘贴到PowerPoint中 xlApp.Worksheets(5).Range("B2:D9").Copy Set shp1 = ActivePresentation.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1) With shp1 ' Set position: .Left = 22 .Top = 95 ' Set size: .Height = 250 .Width =

我使用下面的代码将Excel中的单元格区域作为图像粘贴到PowerPoint中

xlApp.Worksheets(5).Range("B2:D9").Copy
Set shp1 = ActivePresentation.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)

With shp1
' Set position:
.Left = 22
.Top = 95
' Set size:
.Height = 250
.Width = 280
End With
但图像未按定义的大小粘贴,即高度250,宽度280。根据我的理解,它在粘贴时考虑了图像的纵横比,并且不会扭曲图像。但我不想那样。我只想让它覆盖我想要在PowerPoint上显示的整个区域。

在设置宽度和高度之前,需要关闭aspectratio参数:

xlApp.Worksheets(5).Range("B2:D9").Copy
Set shp1 = ActivePresentation.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)

With shp1
' Set position:
.Left = 22
.Top = 95
' Set size:
.Height = 250
.Width = 280
End With
With shp1
' Set position:
.Left = 22
.Top = 95
' Set size:
.LockAspectRatio = msoFalse
.Height = 250
.Width = 280
End With

@crazyfrog,不客气。。。别忘了把答案标为正确答案。完成。。。。如果我可以把我的问题再延长一点。。。与我的代码中指定的excel范围类似,MS excel中有一个表。现在我想要的是复制它,并将其粘贴为MS PowerPoint中的可编辑表。如何更改PasteSpecial的代码?请尝试将的lasta参数设置为true。实际上,它允许我更改数据,但需要转到源excel文件。我希望它允许我在不打开excel文件的情况下更改PowerPoint表格中的数据。此外,它正在创建excel和ppt之间的链接,这是我不想要的