Page 473 - Microsoft Office Excel 2003 Programming Inside Out
P. 473

Excel and Other Office Applications

                             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
                                                                                                             Chapter 21
                             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 info@thegardencompany.com” 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 = "http://www.microsoft.com"
                                 Call ShellExecute(0&, vbNullString, file, vbNullString, vbNullString, _
                                    vbNormalFocus)
                             End Sub















                                                                                                       447
                                                                        Part 6:  Excel and the Outside World: Collaborating Made Easy
   468   469   470   471   472   473   474   475   476   477   478