0

下面的 VBA 代码在 Windows 上打开打印对话框,但在 Mac Excel 2011 上不起作用,在行上给出运行时错误 1004Application.Dialogs(xlDialogPrinterSetup).Show

Private Sub cbPrint_Click()
Dim Caption As String

If formPrintOptions.Frame1.ActiveControl.Value Then
    Caption = formPrintOptions.Frame1.ActiveControl.Caption

    formPrintOptions.Hide
    Application.Dialogs(xlDialogPrinterSetup).Show

    Select Case Caption
        Case "Id1"
            ThisWorkbook.Sheets(Array("FrontPage", "Id1")).PrintOut Preview:=True
        Case "Id2"
            ThisWorkbook.Sheets(Array("FrontPage", "Id2")).PrintOut Preview:=True
        Case "Id3"
            ThisWorkbook.Sheets(Array("FrontPage", "Id3")).PrintOut Preview:=True
        Case "Id4"
            ThisWorkbook.Sheets(Array("FrontPage", "Id4")).PrintOut Preview:=True
        Case Else
    End Select
Else
    MsgBox "None selected"
End If
Unload formPrintOptions

End Sub

请有人建议是否有办法在 Mac Excel 2011 上打开打印对话框窗口?

4

1 回答 1

1

这里有三个选项:

引用

在这种情况下,该功能位于 Mac 正常打印屏幕的“顶部”。“在顶部”既意味着不需要调用从属对话框,也意味着它高于“打印对话框”上的所有其他选项。

或者

Application.Dialogs(xlDialogPrint).Show

或者

MsgBox MacScript(PrintSetupMacScript())

Function PrintSetupMacScript() As String
PrintSetupMacScript = "try"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "tell application ""System Preferences"" "
PrintSetupMacScript = PrintSetupMacScript & vbLf & "    reveal pane ""Print & Fax"" "
PrintSetupMacScript = PrintSetupMacScript & vbLf & "    activate"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "    repeat while (name of window 1) = ""Print & Fax"" "
PrintSetupMacScript = PrintSetupMacScript & vbLf & "   end repeat"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "end tell"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "return true"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "on error"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "return false"
PrintSetupMacScript = PrintSetupMacScript & vbLf & "end try"
End Function

没有Mac来测试这些,我不能保证他们的里程

于 2013-01-14T21:28:58.657 回答