--------------------------------------------------------------------------- QUESTION: --------------------------------------------------------------------------- How do I run files such as web pages, or vbsript files (sample.vbs), or Excel files from within Access or VB? The Shell function only seems to run .exe or .bat files. --------------------------------------------------------------------------- ANSWER: --------------------------------------------------------------------------- You could try the following three humorous but effective methods (all use shell, but with a twist...): (1) SHELL("EXPLORER.EXE sample.vbs") (2) SHELL("START.EXE sample.vbs") (3) SHELL("IEXPLORE.EXE sample.vbs") (4) Use API call to locate executable associated with target file. Option #1 --------- Will send the file to Windows Explorer which looks up the executable associated with the vbs extension, loads it, runs it, and passes the sample.vbs (I sometimes use this for calling up apps and firing off urls when don't want to take time to use API executable lookup.) Option #2 --------- Will only work on Win95 and Win98 machines. If you look in the Windows\Command (DOS 7.0, heh heh) you will find the Start.exe file. This will usually run any app fine from the command line (including long paths, paths will spaces, etc.). Option #3 --------- Will fire up Internet Explorer (bad idea if users might have Netscape) and run the vbs file (I actually tried this one). Users will have to select Save or Open item action (or check the checkbox to never ask again). This is not the best solution. Option #4 --------- This is the best method. It involves passing the target file you want to run to the function below. This function will return the path to the executable associated with the target file. You can then SHELL out to the appropriate executable + target file. USAGE: vRC = Shell(FindExecutable(sDataFileName)) '---------------------------------------------------------------------------------- CODE - Option #4: '---------------------------------------------------------------------------------- 'APIs for FindExecutable '----------------------------------------------------------------------------- Private Declare Function FindExecutableA Lib "shell32.dll" _ (ByVal lpFile As String, ByVal lpdirectory As _ String, ByVal lpResult As String) As Long Private Const MAX_FILENAME_LEN = 256 Public Function FindExecutable(s As String) As String '---------------------------------------------------------------------------------- 'DESCRIPTION: '----------- ' This command will locate the executable associated with the filename passed down ' as a string. '---------------------------------------------------------------------------------- 'INPUT: '------ ' s - The filename whose extension type the API call looks up and returns ' and executable path to. '---------------------------------------------------------------------------------- ' OUTPUT: '-------- ' Executable path associated with the s filename's extension. '---------------------------------------------------------------------------------- ' SAMPLE CALL: '------------- ' vRC = Shell(FindExecutable(sDataFileName)) '---------------------------------------------------------------------------------- ' HISTORY: '--------- ' DOWNLOAD - 09/11/1999 - Downloaded this excellent code from one of the VB sites. '---------------------------------------------------------------------------------- 'DECLARATIONS '------------ Dim i As Integer Dim s2 As String 'INITIALIZE '---------- On Error GoTo ErrHandler 'MAIN BODY '--------- s2 = String(MAX_FILENAME_LEN, 32) & Chr$(0) i = FindExecutableA(s & Chr$(0), vbNullString, s2) If i <= 32 Then GoTo WrapUpErr 'WRAP-UP '------- WrapUp: FindExecutable = Left$(s2, InStr(s2, Chr$(0)) - 1) Exit Function WrapUpErr: FindExecutable = "" Exit Function 'ERROR HANDLER '------------- ErrHandler: Call LogError(True, Err, ModuleName$, "FindExecutable()", "") Resume WrapUpErr End Function