Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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_Vba - Fatal编程技术网

Excel 方法中未定义用户类型宏错误vba

Excel 方法中未定义用户类型宏错误vba,excel,vba,Excel,Vba,我尝试调用子函数,但失败并出现错误: 此行的saveas方法上未定义用户类型。可能未在vba中处理演示文稿 错误出现在SavePDFAsPng的第一行: Dim oPres As Presentation 以下是整个宏: Sub Button1_Click() Call SavePDFAsPng("C:\Users\gfas1\Desktop\ahm.pdf", "C:\Users\gfas1\Desktop\MyTest.PNG") End Sub Sub SavePDFAsPng

我尝试调用子函数,但失败并出现错误:

此行的saveas方法上未定义用户类型。可能未在vba中处理演示文稿

错误出现在
SavePDFAsPng
的第一行:

Dim oPres As Presentation
以下是整个宏:

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

您将问题标记为“Excel”,因此我假设您正在尝试在Excel中运行此宏,但该宏无法运行,因为默认情况下,
演示文稿
类型不在Excel中

在PowerPoint中:

您需要在PowerPoint而不是Excel中运行此宏


您可以在Excel中运行它,但您需要将PowerPoint类型库导入Excel VBA项目,但这是一个单独的问题。

您将问题标记为“Excel”,因此我假设您尝试在Excel中运行此宏,但该宏不起作用,因为默认情况下,
演示文稿
类型不在Excel中

在PowerPoint中:

您需要在PowerPoint而不是Excel中运行此宏


您可以在Excel中运行它,但需要将PowerPoint类型库导入Excel VBA项目,但这是一个单独的问题。

哪一行生成错误?演示文稿。为什么它不处理它?什么类型的
演示文稿
?你有一个类吗?
Dim oPres As Presentation
,据我所知,你不能将变量声明为
Presentation
。不,我没有。这是一个内置的vba,我试着在谷歌上搜索,他们用表示法替换了对象,但仍然不起作用。哪一行产生了错误?表示法。为什么它不处理它?什么类型的
演示文稿
?你有一个类吗?
Dim oPres As Presentation
,据我所知,你不能将变量声明为
Presentation
。不,我没有。这是一个内置的vba,我试着在谷歌上搜索,他们用表示替换了对象,但仍然不起作用