Vba Visual Basic编译错误-无效字符
我在Outlook(2010)中从互联网上获得了一个为辅助电子邮件帐户创建新邮件提醒的机会 这是代码的第一部分,在运行Outlook时,会出现以下错误: “编译错误:无效字符” 调试器在下面一行中的字符下面加下划线:“sndPlaySoundA”Vba Visual Basic编译错误-无效字符,vba,outlook,Vba,Outlook,我在Outlook(2010)中从互联网上获得了一个为辅助电子邮件帐户创建新邮件提醒的机会 这是代码的第一部分,在运行Outlook时,会出现以下错误: “编译错误:无效字符” 调试器在下面一行中的字符下面加下划线:“sndPlaySoundA” 'On the next line change the file name and path of the sound you want to play.' Public Const SOUND_TO_PLAY = "C:\Windows\Media
'On the next line change the file name and path of the sound you want to play.'
Public Const SOUND_TO_PLAY = "C:\Windows\Media\Speech On.wav"
Public Const SND_ASYNC = &H1
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Public Declare Function MessageBox _
Lib "User32" Alias "MessageBoxA" _
(ByVal hWnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) _
As Long
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
' Purpose: Opens an Outlook folder from a folder path.'
' Written: 4/24/2009'
' Author: BlueDevilFan'
' Outlook: All versions'
Dim arrFolders As Variant, _
varFolder As Variant, _
bolBeyondRoot As Boolean
On Error Resume Next
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
Do While Left(strFolderPath, 1) = "\"
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
Loop
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
Select Case bolBeyondRoot
Case False
Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
bolBeyondRoot = True
Case True
Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
End Select
If Err.Number <> 0 Then
Set OpenOutlookFolder = Nothing
Exit For
End If
Next
End If
On Error GoTo 0
End Function
根据您提供的代码示例,您需要在
\uu
之后立即添加一行新行。下划线字符是VBA中的一行延续符(这是您正在使用的,而不是VBScript。稍有不同),因此要求您继续下一行,而不是同一行。所以不是
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Public Declare Function MessageBox _
Lib "User32" Alias "MessageBoxA" _
(ByVal hWnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) _
As Long
你应该
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Declare Function MessageBox _
Lib "User32" Alias "MessageBoxA" _
(ByVal hWnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) _
As Long
编辑:我显然没有一直读到示例行的末尾,否则我会看到示例以某种方式将两个函数声明合并到一行,并且使用了无效的行分隔符定位。我现在已经修好了。太好了,谢谢。但是现在又出现了另一个错误:“编译错误预期:语句结束”,下面的单词突出显示:“Public”…在第二行(…只要Public…@DextrousDave好的,我编辑了答案来解决这个问题。嗯。我真的应该读到那一行的结尾。谢谢。除了一个错误外,所有的错误似乎都已修复,但它不是语法:下面一行的“用户定义类型未定义”:objFM1.FolderToWatch OpenOutlookFolder(“Mailbox-supportdesk\Inbox”)将包含在上面示例中未包含的代码部分中?你能不能也在你的原始帖子中包含这段代码,这样我们也可以看一下呢?但是谢谢你的帮助,你确实回答了我的问题…剩下的只是博努斯我对FolderMonitor不熟悉。它是内置的Outlook类还是单独的库?如果它是单独的,您是否在工具>引用下添加了对它的引用?不,我不认为我添加了…我会看看我能做些什么
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Declare Function MessageBox _
Lib "User32" Alias "MessageBoxA" _
(ByVal hWnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) _
As Long