[英]User type not defined macro error vba in method
I am trying to call a sub function, but fails with an error:我正在尝试调用子 function,但失败并出现错误:
User type not defined on the saveas method at this line.此行的 saveas 方法上未定义用户类型。 Maybe presentation isn't being processed in vba也许演示文稿没有在 vba 中处理
The error is on the first line of SavePDFAsPng
:错误出现在SavePDFAsPng
的第一行:
Dim oPres As Presentation
Here is the whole macro:这是整个宏:
Sub Button1_Click()
Call SavePDFAsPng("C:\Users\gfas1\Desktop\ahm.pdf", "C:\Users\gfas1\Desktop\MyTest.PNG")
End Sub
Sub SavePDFAsPng(sPathToPDF As String, sPathToPNG As String)
Dim oPres As Presentation
Dim oSh As Shape
' Height/Width are hardcoded here
' You could get trickier and bring the PDF into any presentation
' once to get its proportions, delete it, set the slide size to the same
' proportions, then re-insert the PDF
Dim sngWidth As Single
Dim sngHeight As Single
sngWidth = 612
sngHeight = 792
Set oPres = Presentations.Add
With oPres
With .PageSetup ' set it to 8.5x11
.SlideHeight = sngHeight ' 11in * 72 points per inch
.SlideWidth = sngWidth
End With
.Slides.AddSlide 1, .SlideMaster.CustomLayouts(1)
With .Slides(1)
Set oSh = .Shapes.AddOLEObject(0, 0, sngWidth, sngHeight, , sPathToPDF)
Call .Export(sPathToPNG, "PNG")
End With
.Saved = True
.Close
End With
End Sub
You tagged the question with "Excel", so I assume you're trying to run this macro in Excel, which won't work because the Presentation
type is not in Excel by default.你用“Excel”标记了这个问题,所以我假设你试图在 Excel 中运行这个宏,这不起作用,因为Presentation
类型默认不在 Excel 中。
It's in PowerPoint:它在 PowerPoint 中:
https://docs.microsoft.com/en-us/office/vba/api/overview/powerpoint/object-model https://docs.microsoft.com/en-us/office/vba/api/overview/powerpoint/object-model
https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation
You need to run this macro in PowerPoint, not Excel.您需要在 PowerPoint 中运行此宏,而不是 Excel。
You can run it in Excel, but you need to import the PowerPoint type-library into your Excel VBA project, but that's a separate question.您可以在 Excel 中运行它,但您需要将 PowerPoint 类型库导入 Excel VBA 项目,但这是一个单独的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.