问题描述
我正在尝试在Excel 2013中模拟Ctrl-P,其中左侧显示打印对话框,右侧显示打印预览。
(尽管预览显示在哪里,我始终必须先单击";显示打印预览。我找不到强制每次都显示预览的方法)。
我尝试了以下操作:
Application.Dialogs(xlDialogPrint).Show
这将显示需要在其中单击预览按钮的旧样式对话框
ActiveSheet.PrintPreview
这将显示预览,但不允许从同一屏幕更改打印机。
推荐答案
类似的内容?
Excel
Option Explicit
Public Sub Example()
Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint")
End Sub
CommandBars.ExecuteMso Method (MSDN)在特定命令没有对象模型的情况下非常有用。
for Outlook
Option Explicit
Public Sub Example()
Dim Inspector As Outlook.Inspector
Set Inspector = Application.ActiveInspector
If Not Inspector Is Nothing Then
Dim cmd As Office.CommandBars
Set cmd = Inspector.CommandBars
cmd.ExecuteMso ("FilePrintPreview")
Else
ActiveExplorer.selection(1).Display
Set cmd = ActiveInspector.CommandBars
cmd.ExecuteMso ("FilePrintPreview")
End If
End Sub