|
|
|
|
|
|
Excel
|
Select Program to Open a File
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2002
|
Submitted by:
|
Justinlabenne
|
Description:
|
Select the program you want to open a certain file with
|
Discussion:
|
When opening a certain file, you may want to select a certain program to open the file with. This code shows the "Open With" dialog allowing the user to select what program to use when opening a pre-selected file.
The example workbook contains the code workbook, and an example text file which designated as the file to open.
|
Code:
|
instructions for use
|
Option Explicit
Sub OpenHow()
Dim szFileToOpen As String
szFileToOpen = ThisWorkbook.Path & "\tester.txt"
Dim szOpenWith As String
szOpenWith = "rundll32.exe shell32.dll,OpenAs_RunDLL " & szFileToOpen
Dim vRun As Variant
vRun = Shell(szOpenWith, vbMaximizedFocus)
End Sub
|
How to use:
|
- Open an Excel Workbook
- Copy the code
- Press Alt + F11 to open the Visual Basic Editor (VBE)
- Select INSERT > MODULE from the menubar
- Paste code into the right pane
- Press Alt+Q to return to Excel
- Save workbook before any other changes
|
Test the code:
|
- The example uses a text file that is assumed to be in the same location as the Excel workbook and is named {tester.txt}
-
- You can incorporate any fixed file path or browse for file routine into the code to allow for selecting of other files.
-
- Go to TOOLS > MACRO > MACROS
- When the dialog appears, select {OpenHow}
- Press Run
|
Sample File:
|
RunWithIt.zip 6.5KB
|
Approved by mdmackillop
|
This entry has been viewed 275 times.
|
|