0

可以不使用单词“Shell32.dll”编写文件打印例程,因为在我的受保护的 VBA 中的 XLSB 文件中使用它会标记 Excel 文件包含与木马相关的脚本,并且无法通过电子邮件发送或下载 Excel 文件。

导致木马错误消息的现有代码。

Option Explicit

#If VBA7 Then
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#Else
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If

Public Const SW_HIDE = 0

Sub PrintFile(ByVal strFilePath As String)

    Dim retVal As Long
    retVal = ShellExecute(0, "Print", strFilePath, 0, 0, SW_HIDE)

    If retVal < 32 Then
        MsgBox "An error occured...Could not print"
        With Application
           .EnableEvents = True
           .ScreenUpdating = True
        End With
    End If

End Sub
4

1 回答 1

0

VBA 标准库包含一个围绕该 API 函数的薄包装器Shell,在VBA.Interaction模块中方便地命名为 ——也许这对您有用?

result = Shell("print " & path, vbHide)
于 2017-04-25T19:26:30.637 回答