我有一个文本框,用于收集条形码扫描仪的输入。收集的代码与附加工作表交叉引用,如果匹配,则打印相应的PDF文件。
我的问题是,在打印PDF文件后,我无法将焦点返回到Excel窗口,以便可以立即扫描另一个条形码。我尝试过使用AppActivate,这似乎不起作用。请参阅以下代码:
Private Sub txtscanbox_Change()
Dim c, code
If Len(txtscanbox.Value) = 13 Then
code = txtscanbox.Value
With Sheets("urlLookup").Range("A:A")
Set c = .Find(code, LookIn:=xlValues)
If Not c Is Nothing Then
Dim filePath
filePath = ActiveWorkbook.Path + "\" + CStr(c.Offset(0, 1)) + ".pdf"
CreateObject("Shell.Application").Namespace(0).ParseName(filePath).InvokeVerb ("Print")
Label1.Caption = "Retrieved: " + code
Label2.Caption = "Order: " + CStr(c.Offset(0, 1))
Else: MsgBox "This order was not found"
End If
End With
With Me.txtscanbox
.SetFocus
.Text = ""
End With
End If
End Sub