0

Can a file printing routine be written not using the word "Shell32.dll" as using this within my protected VBA within an XLSB file is flagging that the Excel file contains a Trojan related script and is not able to email or download the excel file.

Existing code causing the Trojan error message.

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
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Alan
  • 1
  • 1

1 Answers1

0

The VBA standard library contains a thin wrapper around that API function, conveniently named Shell, in the VBA.Interaction module - maybe this can work for you?

result = Shell("print " & path, vbHide)
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235