Excel VBA UserForm打印屏幕另存为pdf



我有UserForm,我有一个按钮来打印UserForm的屏幕,粘贴到新创建的工作表中,并将其导出为pdf。我对当前代码的问题是:

1( 我想将打印屏幕调整为一页,现在它需要打印屏幕并拆分为两页。

2( 打印屏幕分辨率更高。是否可以提高打印屏幕的分辨率以获得更高的质量?

我在UserForm上用于按钮的代码:

Private Sub btnPrintPDF_Click()
'change to your button name
Dim pdfName As String
Dim newWS As Worksheet
Application.DisplayAlerts = False
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
DoEvents 'Otherwise, all of screen would be pasted as if PrtScn rather than Alt+PrtScn was used for the copy.
Set newWS = ThisWorkbook.Worksheets.Add(After:=Worksheets(Worksheets.Count))
newWS.PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False
pdfName = ThisWorkbook.Path & "" & Sheets("MAIN").Range("D14").Value & "Project_Summary" & "_" & " " & Format(Now, "yyyy-mmm-dd") & ".pdf"
newWS.ExportAsFixedFormat Type:=xlTypePDF, _
FileName:=pdfName, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
newWS.Delete
Unload Me
Application.DisplayAlerts = True
ThisWorkbook.Sheets("MAIN").Activate
End Sub
Application.PrintCommunication = False
With newWS.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
End With
Application.PrintCommunication = True
ewWS.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=pdfName, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False

相关内容

  • 没有找到相关文章

最新更新