Microsoft Office Tutorials and References
In Depth Information
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
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
Search JabSto ::




Custom Search