All blog posts, code samples and downloads licensed under Apache License 2.0.
Close

Open a non-executable file in VBA

Oliver Busse on 02/07/2014 11:07:48 CET, filed under Misc VBA 

I ran into the problem to execute (e.g. open a file) in VBA that is not executable, so you cannot use Shell to run it.

In my case I wanted to open a HTML file (the reference help from Office 2010) from a button in a ribbon group.

So this is the way I finally did it. Thanks to my colleague beside me Lächelnd

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long

sub mySub()
Call ShellExecute(GetDesktopWindow(), "Open", myTempPath & TempFileName, "", myTempPath, 1) 
end sub

Tagged with vba execute html reference office 2010