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

Microsoft Office Excel 2003 Programming Inside Out

                             In the following example, The Garden Supply Company has a list of pictures used in their
                             spring catalog. You have been asked to create a worksheet that allows the user to choose the
                             images and insert a preview into the worksheet.

                             Important  The following two procedures assume there is a worksheet named
             Chapter 13
                             ImagePreview in the active workbook.

                             Private Sub cmdGetFile_Click()
                                 Dim FD As FileDialog
                                 Dim FFs As FileDialogFilters
                                 Dim strFileName As String
                                 On Error GoTo Problem

                                 Set FD = Application.FileDialog(msoFileDialogOpen)

                                 With FD
                                    Set FFs = .Filters
                                    With FFs
                                        .Clear
                                        .Add “Pictures", “*.jpg"
                                    End With

                                    If .Show = False Then Exit Sub
                                    Worksheets(“ImagePreview”).Pictures.Insert (.SelectedItems(1))
                                 End With

                                 Exit Sub

                             Problem:
                                 MsgBox “You have not selected a valid picture."
                             End Sub

                             The FileDialog property of the Application object returns a reference to the Office FileDialogs
                             object. Table 13-5 lists the msofileDialogType constants available to specify the type of dialog.

                             Table 13-5.  List of Dialog Types and Their Values
                             msoFileDialog Constants                   Value
                             msoFileDialogOpen                         1
                             msoFileDialogSaveAs                       2
                             msoFileDialogFilePicker                   3
                             msoFileDialogFolderPicker                 4




                292
             Part 4:  Advanced VBA
   313   314   315   316   317   318   319   320   321   322   323