简体   繁体   English

Excel to Powerpoint:调整图像大小

[英]Excel to Powerpoint: Issue Resizing image

Hello I am try to copy an image from excel into powerpoint. 您好,我尝试将图像从Excel复制到PowerPoint。 My code already copy and pastes into excel but I am having an issue with the code that would automate the resizing. 我的代码已经复制并粘贴到excel中,但是我的代码存在问题,无法自动调整大小。 With this current code I get object required Runtime error 424. Any help would be appreciated. 使用此当前代码,我得到了对象必需的运行时错误424。任何帮助将不胜感激。 MY abbreviated code is below. 我的缩写代码如下。

Sub CopyDataToPPT()
'Const ppLayoutBlank = 12
Dim objWorkSheet As Worksheet
Dim objRange As Range
Dim objPPT As PowerPoint.Application
Dim objPresentation As Presentation
Dim shapePPTOne As Object
Dim intLocation As Integer
Dim intHeight As Integer
Dim inLayout As Integer
Dim strRange As String
Dim boolOK As Boolean
Set objPPT = CreateObject("PowerPoint.Application")
Set objPresentation = objPPT.Presentations.Add

 'First 1 Xor 2 charts
    If Sheets("Summary Table").Cells(15, 4) <> "Not Found" Then
        strRange = "B4:N24"
        intHeight = 380
    Else
        strRange = "B4:N13"
        intHeight = 190
    End If

    Set objslide = objPresentation.Slides.Add(1, inLayout)
    objPresentation.Slides(1).Layout = ppLayoutTitleOnly

    objPresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Text = Sheets("Summary Table").Cells(2, 5) & " - " & Sheets("Summary Table").Cells(4, 2)
    Set objRange = Sheets("Summary Table").Range(strRange)
    objRange.Copy

    DoEvents
    Set shapePPTOne = objslide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile, Link:=msoFalse)

    shapePPTOne.Height = intHeight
    shapePPTOne.Left = 50
    shapePPTOne.Top = 100

    Application.CutCopyMode = False
Next intLocation

This (a simplified version of your code) works fine for me: 这(您的代码的简化版本)对我来说很好用:

Sub CopyDataToPPT()

Dim objslide
Dim objRange As Range
Dim objPPT As PowerPoint.Application
Dim objPresentation As Presentation
Dim shapePPTOne As Object


    Set objPPT = CreateObject("PowerPoint.Application")
    Set objPresentation = objPPT.Presentations.Add

    Set objslide = objPresentation.Slides.Add(1, ppLayoutTitleOnly) 'you had inLayout???
    objslide.Shapes.Title.TextFrame.TextRange.Text = "blah blah"

    Sheets("Sheet1").Range("C6:G22").Copy
    DoEvents

    Set shapePPTOne = objslide.Shapes.PasteSpecial( _
                DataType:=ppPasteEnhancedMetafile, Link:=msoFalse)

    With shapePPTOne
        .Height = 200
        .Left = 50
        .Top = 100
    End With

    Application.CutCopyMode = False

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM