我尝试在VBA(Word 2010)中使用SendKeys来填充某些第三方传真软件的对话框。下面的代码显示传真对话框,它有焦点,光标在我要发送数据的字段中闪烁。但实际上数据会被发送到Word文档(或代码编辑器 - 无论从哪里调用sub)。如何防止这种情况并填充对话框?
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub RightFax()
With Dialogs(wdDialogFilePrintSetup)
.Printer = "RightFax Fax Printer"
.DoNotSetAsSysDefault = True
.Execute
End With
SendKeys "{Enter}"
Sleep 500 'test - prints in word doc or code editor
SendKeys "TEST AAA"
Sleep 500
With Dialogs(wdDialogFilePrint)
.Show
End With
Sleep 500 'test - prints in word doc or code editor
SendKeys "TEST BBB"
End Sub