我正在尝试运行以下宏并在勾选复选框时打印文件。
Option Explicit
Declare Function apiShellExecute 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
Public Sub PrintFile(ByVal strPathAndFilename As String)
Call apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0)
End Sub
Sub set_print2()
Dim cBox As CheckBox
Dim LRow As Integer
Dim LRange As String
Dim LName As String
Dim Path As String
LName = Application.Caller
Set cBox = ActiveSheet.CheckBoxes(LName)
'Find row that checkbox resides in
LRow = cBox.TopLeftCell.Row
LRange = "R" & CStr(LRow)
Path = Range(LRange).Value
'Change date in column B, if checkbox is checked
If cBox.Value > 0 Then
'To set the detfault:
Dim WshNetwork As Object
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter "\\GB-240AS02\SafeQPrinter"
MsgBox Application.ActivePrinter
' print document, then go back to the original printer
PrintFile (Path)
AVDoc.Close (True)
AcroApp.Hide
Set AcroApp = Nothing
Set AVDoc = Nothing
'Clear date in column B, if checkbox is unchecked
Else
Exit Sub
End If
End Sub
由于某些原因,我在下一行收到错误'未定义的变量':
AVDoc.Close (True)
请有人告诉我我哪里出错了吗?感谢