2013-05-21 118 views
0

我得到了一個VB SCRIPT在互聯網上創建Outlook(2010)中的輔助電子郵件帳戶的新郵件提醒。Visual Basic編譯錯誤 - 無效字符

現在,這是代碼的第一部分,並運行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\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 

更新:一個新的錯誤已經上升:(之後我「sndPl後固定在1號線新線問題aySoundA「)由以下阿德里安)refered到

」編譯錯誤預期:語句結束「 和下列字突出顯示: 」公「

UPDATE2:下一個錯誤:

編譯錯誤:用戶定義類型沒有定義(對於「郵箱 - supportdesk \收件箱」)

Dim objFM1 As FolderMonitor 

Private Sub Application_Quit() 
    Set objFM1 = Nothing 
End Sub 

Private Sub Application_Startup() 
    Set objFM1 = New FolderMonitor 
    'Edit the folder path on the next line as needed.' 
    objFM1.FolderToWatch OpenOutlookFolder("Mailbox - supportdesk\Inbox") 
    End Sub 
+0

我不熟悉FolderMonitor。它是內置的Outlook類還是單獨的庫?如果它是分開的,您是否在工具>參考下添加了對它的引用? – Adrian

+0

不,我認爲我沒有...會看到我能做什麼 – DextrousDave

回答

1

根據您提供有您需要的_後新行的代碼示例。下劃線字符是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 

編輯:我明明沒有一路讀到這個例子行的末尾,否則我會看到的例子以某種方式設法將兩個函數聲明混合到一行中以及使用行分隔符的無效定位。我現在已經解決了這個問題。

+0

很酷謝謝你。但現在又出現了另一個錯誤:「編譯錯誤預期:語句結束」,下面的單詞被突出顯示:「Public」...在第二行(... As Long Public ...) – DextrousDave

+0

@DextrousDave好吧,已經編輯瞭解決這個問題的答案。咄。我真的應該讀到該行的結尾。 – Adrian

+0

謝謝。似乎所有的錯誤現在都被修復,除了一個,但它不是語法:它說:「用戶定義的類型未定義」爲下面的行:objFM1.FolderToWatch OpenOutlookFolder(「郵箱 - 支持臺\收件箱」) – DextrousDave