依次打印2个用户表单

时间:2019-03-04 20:09:42

标签: excel vba pdf userform

我发现以下代码生成了Userform的PDF(在将其复制到Excel工作表之后)。

Application.ScreenUpdating = False
Path = "C:\Users\" & Environ("USERNAME") & "\Desktop\"
Application.SendKeys "(%{1068})"
DoEvents
Workbooks.Add
ActiveSheet.PasteSpecial
ActiveSheet.Range("A1").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & Me.Name & ".pdf"
UserForm1.Hide
ActiveWorkbook.Close False
Application.ScreenUpdating = True

如果我有2种用户表格怎么办?

我想打印userform1,打开userform2并从中制作pdf吗?

我尝试了以下操作,但是它在打开userform2之前捕获了屏幕。

Private Sub CommandButton8_Click()
    Application.ScreenUpdating = False
    Path = "C:\Users\" & Environ("USERNAME") & "\Desktop\"
    Application.SendKeys "(%{1068})"
    DoEvents
    Workbooks.Add
    ActiveSheet.PasteSpecial
    ActiveSheet.Range("A1").Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & Me.Name & ".pdf"
    UserForm1.Hide
    ActiveWorkbook.Close False
    Application.ScreenUpdating = True

    UserForm2.Show
    Application.ScreenUpdating = False
    Path = "C:\Users\" & Environ("USERNAME") & "\Desktop\"
    Application.SendKeys "(%{1068})"
    DoEvents
    Workbooks.Add
    ActiveSheet.PasteSpecial
    ActiveSheet.Range("A1").Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & Me.Name & "2.pdf"
    UserForm1.Hide
    ActiveWorkbook.Close False
    Application.ScreenUpdating = True
End Sub

或者,甚至更好的是,如何将userform1粘贴在userform2之下,然后再将两者粘贴成1个长PDF?

谢谢

0 个答案:

没有答案