|
我设计了一个BA地址来新邮件自动弹框的代码,我还希望有声音提醒,声音一直到我对电脑进行某些操作(如按键盘某键,如ESC键)时才停下,我用了循环语句,但不知道如何用VBA代码来表示我要对电脑进行“按键盘”的操作,结果代码进入死循环,我按CTRL+BREAK可以停止,但新邮件自动弹框的程序也停止了,请教高手有什么办法来控制这个循环,或是有新的方法,来控制声音的播放?
Dim myOlApp As New Outlook.Application
'Public WithEvents myOlItems As Outlook.Items
Public WithEvents myOlItems1 As Outlook.Items
Private Declare Function PlayWaveSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszsoundname As String, ByVal uflags As Long) As Long
Public Sub Application_Startup()
'Set myOlItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("BA").Folders("GLB1").Folders("GLBGSCOFAC").Items
Set myOlItems1 = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("BA").Folders("SZH2").Folders("SZHGSCSCVEREG").Items
End Sub
'Sub myOlItems_ItemAdd(ByVal Item As Object)
'With UserForm1
'.Label1.Caption = "OFAC new mail receipt on " & Now
'.Repaint
'End With
'UserForm1.Show
'End Sub
Sub myOlItems1_ItemAdd(ByVal Item As Object)
With UserForm2
.Label1.Caption = "EREG new mail receipt on " & Now
.Repaint
End With
Do
soundName = "C:\WINDOWS\media\ringin.wav" '指定声音文件
PlayWaveSound soundName, 0
Loop
UserForm2.Show
End Sub |
|