vba - Visual Basic Compile Error - Invalid Character -


i got vb script off internet create new mail alerts secondary email accounts in outlook(2010).

now first part of code, , when running outlook, gives me following error:

"compile error: invalid character"

the debugger underlines _ character in following line: "sndplaysounda" _

'on next line change file name , path of sound want 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 string, byval uflags long) long public declare function    messagebox _     lib "user32" alias "messageboxa" _         (byval hwnd long, _         byval lptext string, _         byval lpcaption string, _         byval wtype long) _     long   function openoutlookfolder(strfolderpath string) outlook.mapifolder     ' purpose: opens outlook folder folder path.'     ' written: 4/24/2009'     ' author:  bluedevilfan'     ' outlook: versions'     dim arrfolders variant, _         varfolder variant, _         bolbeyondroot boolean     on error resume next     if strfolderpath = ""         set openoutlookfolder = nothing     else         while left(strfolderpath, 1) = "\"             strfolderpath = right(strfolderpath, len(strfolderpath) - 1)         loop         arrfolders = split(strfolderpath, "\")         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                 set openoutlookfolder = nothing                 exit             end if         next     end if     on error goto 0 end function 

update: new error has risen: (after fixed new line issue on line 1 after "sndplaysounda") refered adrian below)

"compile error expected: end of statement" , following word highlighted: "public"

update2: next error:

compile error: user defined type not defined(for "mailbox - supportdesk\inbox")

dim objfm1 foldermonitor  private sub application_quit()     set objfm1 = nothing end sub  private sub application_startup()     set objfm1 = new foldermonitor     'edit folder path on next line needed.'     objfm1.foldertowatch openoutlookfolder("mailbox - supportdesk\inbox")     end sub 

according code sample you've provided there need new line after _. underscore character line continuation in vba (which you're using, not vbscript. different beasts) , requires continue on next line, not same line. instead of

public declare function sndplaysound lib "winmm.dll" alias "sndplaysounda" _ (byval lpszsoundname string, byval uflags long) long public declare function messagebox _ lib "user32" alias "messageboxa" _     (byval hwnd long, _     byval lptext string, _     byval lpcaption string, _     byval wtype long) _ long 

you should have

public declare function sndplaysound lib "winmm.dll" alias "sndplaysounda" _  (byval lpszsoundname string, byval uflags long) long   public declare function messagebox _ lib "user32" alias "messageboxa" _     (byval hwnd long, _     byval lptext string, _     byval lpcaption string, _     byval wtype long) _ long 

edit: didn't read way end of example line, or else have seen example somehow managed mash 2 function declarations onto 1 line using invalid positioning of line separator. i've fixed now.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -