Private Const ERROR_FILE_NOT_FOUND = 2 'The specified file was not found. '0 'The operating system is out of memory or resources. Public Declare Function ShellExecute Lib "shell32.dll" _ MsgBox "Path not found" Case ERROR_BAD_FORMAT MsgBox "File not found" Case ERROR_PATH_NOT_FOUND
LRetVal = ShellExecute(0, "open", sURL, "", "", SW_SHOWNORMAL)Ĭase Is > SE_ERR_DLLNOTFOUND 'If the function succeeds, it returns a value greater than 32 'Success Case ERROR_FILE_NOT_FOUND 'OpenUR元 "" 'OpenUR元 "C:\Users\Microsoft\Documents\Test.pdf" -> launches in system default app 'OpenUR元 "C:\Users\Microsoft\Documents\Image.jpg" -> launches in system default app '***Reports of issues in which URL is passed as lowercase causing issues with certain case sensitive URLs*** Public Sub OpenUR元( ByVal sURL As String)ĭim lRetVal As Long 'lpOperation can be: edit, explore, find, open, print, runas Private Const SE_ERR_SHARE = 26 'A sharing violation occurred. Private Const SE_ERR_PNF = 3 'The specified path was not found. Private Const SE_ERR_OOM = 8 'There was not enough memory to complete the operation. This error will also be ' returned if you attempt to print a file that is not printable. Private Const SE_ERR_NOASSOC = 31 'There is no application associated with the given file name extension. Private Const SE_ERR_FNF = 2 'The specified file was not found. Private Const SE_ERR_DLLNOTFOUND = 32 'The specified DLL was not found. Private Const SE_ERR_DDETIMEOUT = 28 'The DDE transaction could not be completed because the request timed out. Private Const SE_ERR_DDEFAIL = 29 'The DDE transaction failed. Private Const SE_ERR_DDEBUSY = 30 'The DDE transaction could not be completed because other DDE transactions were being processed. Private Const SE_ERR_ASSOCINCOMPLETE = 27 'The file name association is incomplete or invalid. Private Const SE_ERR_ACCESSDENIED = 5 'The operating system denied access to the specified file. Private Const ERROR_BAD_FORMAT = 11 'The. Private Const ERROR_PATH_NOT_FOUND = 3 'The specified path was not found. 'ShellExecute Return Codes '0 'The operating system is out of memory or resources. ) As Long 'ShellExecute nShowCmd values Public Const SW_HIDE = 0 ' Public Declare Function ShellExecute Lib "shell32.dll" _
#Shellexecute api vba access code
All that to say, the code can be somewhat simplified.
I’ve supplied all the constants according to the available documentation, but obviously you don’t need to carry all of them around if you don’t plan on ever using them. Public Sub OpenURL2(ByVal sURL As String)Īnother option is to use the ShellExecute API. 'OpenURL2 "C:\Users\Microsoft\Documents\Image.jpg" -> launches in system default app 'OpenURL2 "C:\Users\Microsoft\Documents\Test.pdf" -> launches in system default app ) As Long 'OpenURL2 "" 'OpenURL2 "C:\Users\Microsoft\Documents\Test.pdf" -> launches in system default app 'OpenURL2 "C:\Users\Microsoft\Documents\Image.jpg" -> launches in system default app Public Sub OpenURL2( ByVal sURL As String) Public Declare Function FileProtocolHandler Lib "url.dll" _ FileProtocolHandler APIĪnother option is to use the FileProtocolHandler API. That said, for me, this lead me to start exploring what other options existed and that is for where the rest of this article originated from.
Disable “Hyperlinks can be harmful to your computer and data” Message in Office 2016.
Enable or disable hyperlink warning messages in 2007 Office programs and in Office 2010 programs.
#Shellexecute api vba access free
Now there are ways to deactivate such messages, but the you get into hacking the registry and not everyone has the necessary permissions, ... Should wish to explore this more, feel free to look over: To protect your computer, click only those hyperlinks from trusted sources. Hyperlinks can be harmful to your computer and data. The only problem being that depending on Microsoft’s mood, registry settings, ... some users will get the following warning which can be alarming to some: 'OpenURL1 "C:\Users\Microsoft\Documents\Image.jpg" -> launches in system default app 'OpenURL1 "C:\Users\Microsoft\Documents\Test.pdf" -> launches in system default app 'OpenURL1 "" 'OpenURL1 "C:\Users\Microsoft\Documents\Test.pdf" -> launches in system default app 'OpenURL1 "C:\Users\Microsoft\Documents\Image.jpg" -> launches in system default app Function OpenURL1( ByVal sURL As String)