
Open a file open dialog in Project
I post a request but the samples provided don't work.
What are the prerequisite?
My
VBA environment seems properly referenced.
Do we need to initialize the object variable if yes How
do you do that
Here the 3 sample. If you copy and paste them in the
global.mpt none of them works.
Can someone help me ?
The goal is to provide the user a window open dialog box
for Window Xp or NT users.
Thanks for you help.
Sample 1
Sub openDialog()
Dim cdl As CommonDialog
Set cdl = New CommonDialog
cdl.initdir = "C:\"
cdl.Flags = cdlOFNAllowMultiSelect Or
cdlOFNNoChangeDir
cdl.ShowOpen
'..............
Set cdl = Nothing
End Sub
Sample two
Sub Macrofileop()
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Dim oproj As Object
'Create a FileDialog object as a File Picker dialog
box.
Set fd = Application.FileDialog
(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is a
String,
'the variable must be a Variant because For
Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the
FileDialog object.
With fd
'Use the Show method to display the File Picker
dialog box
'The user pressed the action button.
If .Show = -1 Then
'Step through the FileDialogSelectedItems
collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem contains the path of
each selected item.
'Here use any file I/O functions you want
on the path.
'This example simply displays the path in
a message box.
MsgBox "The path is: " & vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Sample 3
-----------------
Sub DisplayAndExecuteFileDialog(ByRef fd As FileDialog)
'Use a With...End With block to reference the
FileDialog object.
With fd
'If the user presses the action button...
If .Show = -1 Then
'Use the DialogType property to determine
whether to
'use the Execute method.
Select Case .DialogType
Case msoFileDialogOpen,
msoFileDialogSaveAs: .Execute
'Do nothing otherwise.
Case Else
End Select
'If the user presses Cancel...
Else
End If
End With
End Sub