Microsoft Office Tutorials and References
In Depth Information
You’re able to achieve the same results using the Start command within your VBA code. For
example, a sales representative from The Garden Company can launch PowerPoint and open
a Marketing presentation file from Excel. Review the code that follows to see how to achieve
these results.
Note The following example will work if you are using an operating system previous to
Microsoft Windows NT. If you have Microsoft Windows NT or later, you will need to use the
ShellExecute function to achieve the same results. The ShellExecute function is explained in
the next example. Although you need Microsoft Windows 2000 or Windows XP (or later) to
run Excel 2003, this procedure will work if you’re trying to run Excel 2003 code in an older
version of Excel. There might, of course, be other incompatibilities.
Sub OpenPresentation()
Filename = "C:\Garden Supply Company\Marketing\Fall Initiative.ppt"
Shell "Start " & Filename
End Sub
Tip Automating Mail
To send an e-mail message using VBA code, the Start command is an effective way to start
the message. Use Shell "Start” to start the default
mail client. If you are using Windows NT or later, you will need to replace the Shell
command with the ShellExecute function.
Because the Start command isn’t available with Windows NT or later operating systems, you
need to use the ShellExecute function to achieve similar results. The following example uses
the ShellExecute function to open Microsoft’s home page:
Private Declare Function ShellExecute Lib "shell32.dll” Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperations As String, ByVal lpfile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Sub OpenFile()
File = ""
Call ShellExecute(0&, vbNullString, file, vbNullString, vbNullString, _
End Sub
Search JabSto ::

Custom Search