[英]Create PDF compile error “Application: defined or object-defined error”
I have a VBA userform where the user searches the database sheet for certain terms.我有一个 VBA 用户表单,用户可以在其中搜索数据库表中的某些术语。 It generates the result in a separate sheet and when the user clicks the print button it creates a PDF that includes all the data in the search result sheet.它在单独的表中生成结果,当用户单击打印按钮时,它会创建一个 PDF,其中包括搜索结果表中的所有数据。
It is giving the compile error它给出了编译错误
"Application: defined or object-defined error" “应用程序:定义的或对象定义的错误”
Sub CreatePDF()
Sheet4.Select
Range("A1:N25").Select
ThisWorkbook.Sheets("SearchData").Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="D:\AliBinAli\Security Visitor App\temp.pdf", _
Quality:=xlQualityStandard, _
Orientation:=xlLandscape, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheet4.Select
Range("A1").Select
End Sub
The highlighted line is:突出显示的行是:
Selection.ExportAsFixedFormat _ Type:=xlTypePDF, _
Filename:="D:\AliBinAli\Security Visitor App\temp.pdf", _
Quality:=xlQualityStandard, _
Orientation:=xlLandscape, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
There is no Orientation
argument in the Worksheet.ExportAsFixedFormat method
. Worksheet.ExportAsFixedFormat method
中没有Orientation
参数。
You could try this:你可以试试这个:
Option Explicit
Sub CreatePDF()
With ThisWorkbook.Worksheets("SearchData")
.PageSetup.Orientation = xlLandscape
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="D:\AliBinAli\Security Visitor App\temp.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
With Sheet4
.Activate
.Range("A1").Select
End With
End Sub
or if you wanted to print the range:或者如果您想打印范围:
Sub CreatePDF2()
With Sheet4.Range("A1:N25")
.Worksheet.PageSetup.Orientation = xlLandscape
.Orientation = xlHorizontal
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="D:\AliBinAli\Security Visitor App\temp.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
.Worksheet.Activate
.Cells(1).Select
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.