Use of FileDialog Object

B

B.P.B.

I would like to use the FileDialog object that is available in Office 10 in a Project 2003 VBA app. However, how one creates an instance of FileDialog in my program is puzzling me. In Excel, FileDialog appears as a member of Application, whereas it does not in Project 2003. Thus in Excel, one does a Set fd = Application.FileDialog(msoFileDialogOpen) for example and fd is instantiated. How to do that in Project where FileDialog is not a member of Application?
 
G

Gérard Ducouret

Have you tried the FileOpen method ?

Gérard Ducouret

B.P.B. said:
I would like to use the FileDialog object that is available in Office 10
in a Project 2003 VBA app. However, how one creates an instance of
FileDialog in my program is puzzling me. In Excel, FileDialog appears as a
member of Application, whereas it does not in Project 2003. Thus in Excel,
one does a Set fd = Application.FileDialog(msoFileDialogOpen) for example
and fd is instantiated. How to do that in Project where FileDialog is not a
member of Application?
 
B

B.P.B

Thanks for the suggestion, Gerard, but I want to browse for and then open an Excel file. FileOpen seems to be designed for opening another Project file, e.g. it doesn't seem to let one specify file types like "*.xls". I have come up with a crude but effective workaround, which is to use Excel's Application object (which contains a FileDialog property) to instantiate the FileDialog object in Project, since I am referencing Excel library objects anyway. Furthermore, I have not been successful in instantiating the FileDialog object in Project by using New either. Why Microsoft would choose not to offer the FileDialog property in the Project Application object is puzzling to me. I thought that Office objects were supposed to be uniformly creatable across the Office product line.
 
G

Gérard Ducouret

Hello,

Have a look to the following procedure. I'll try to find something else...

Gérard

Sub Ouvre_XL()
Dim FichierXL As String, i As Integer

OptionsSchedule DurationUnits:=pjMinutes, EffortDriven:=False

Rep = "C:\Documents and Settings\Administrateur\Mes documents\"
OptionsSave DefaultProjectsPath:=Rep

FichierXL = Dir(Rep & "*.XLS") 'Lit le premier classeur Excel .XLS
du répertoire

If Len(FichierXL) = 0 Then
MsgBox "Aucun Classeur Excel dans ce répertoire, " & Chr(13) &
"Modifiez le répertoire de recherche", vbCritical, "Sélection de fichier
Excel pour import dans Project..."
Exit Sub
End If

Load UF_ListeXL 'Charge la boîte de dialogue
"UF_ListeXL"
UF_ListeXL.Show 'vbModeless 'Affiche la boîte Non Modale
(Version >= 2000 seulement)

End Sub


B.P.B said:
Thanks for the suggestion, Gerard, but I want to browse for and then open
an Excel file. FileOpen seems to be designed for opening another Project
file, e.g. it doesn't seem to let one specify file types like "*.xls". I
have come up with a crude but effective workaround, which is to use Excel's
Application object (which contains a FileDialog property) to instantiate the
FileDialog object in Project, since I am referencing Excel library objects
anyway. Furthermore, I have not been successful in instantiating the
FileDialog object in Project by using New either. Why Microsoft would choose
not to offer the FileDialog property in the Project Application object is
puzzling to me. I thought that Office objects were supposed to be uniformly
creatable across the Office product line.
 
G

Gérard Ducouret

Another one :

Sub ClasseurXLOuvrir()
OptionsSchedule DurationUnits:=pjMinutes, EffortDriven:=False

Rep = "C:\Documents and Settings\Administrateur\Mes documents\"
OptionsSave DefaultProjectsPath:=Rep

SendKeys "{TAB}", False
SendKeys "{DOWN 8}", False
SendKeys "{ENTER}", False
FileOpen ReadOnly:=False, Merge:=3, FormatID:="MSProject.XLS8",
map:="Mappage XX"

End Sub

Gérard
 
G

Gérard Ducouret

A third one, from an idea of Karl Stewing

Sub Karl_STEWING()

Dim oXL As Excel.Application
Dim oDialog As Office.FileDialog

Set oXL = New Excel.Application
Set oDialog = oXL.FileDialog(msoFileDialogFilePicker)
oDialog.Filters.Add "Fichiers Excel", "*.xls"
oDialog.Title = "Sélectionnez le fichier Excel"
oDialog.AllowMultiSelect = False
oDialog.Show
If oDialog.SelectedItems.Count > 0 Then
MsgBox oDialog.SelectedItems(1)
End If
Set oDialog = Nothing
Set oXL = Nothing

'Ceci permet de garder la main sur les évenements. Ensuite, il faut ouvrir
le
'fichier Excel manuellement. En utilisant msoFileDialogOpen au lieu de
'msoFileDialogFilePicker, il y peut-être moyen de rendre ca plus efficace.

'GetOpenFileName

End Sub
 
R

Rod Gill

Hi,

To open the Windows File Open dialog and return the selected file, you
either need to use Excel's GetFileOpen method or call the Window's API.
Calling the API works in all versions of Project (98 onwards) and doesn't
require instantiating an Excel object.

To get sample code for calling the API visit:
http://www.mvps.org/access/api/index.html

I've used it as is and it works fine.

--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
B.P.B said:
Thanks for the suggestion, Gerard, but I want to browse for and then open
an Excel file. FileOpen seems to be designed for opening another Project
file, e.g. it doesn't seem to let one specify file types like "*.xls". I
have come up with a crude but effective workaround, which is to use Excel's
Application object (which contains a FileDialog property) to instantiate the
FileDialog object in Project, since I am referencing Excel library objects
anyway. Furthermore, I have not been successful in instantiating the
FileDialog object in Project by using New either. Why Microsoft would choose
not to offer the FileDialog property in the Project Application object is
puzzling to me. I thought that Office objects were supposed to be uniformly
creatable across the Office product line.
 
L

Lars Hammarberg

Use the FileDialog method of the Office object (as it is - just as you
said - an Office thing)

/Lars Hammarberg
www.camako.se

B.P.B. said:
I would like to use the FileDialog object that is available in Office 10
in a Project 2003 VBA app. However, how one creates an instance of
FileDialog in my program is puzzling me. In Excel, FileDialog appears as a
member of Application, whereas it does not in Project 2003. Thus in Excel,
one does a Set fd = Application.FileDialog(msoFileDialogOpen) for example
and fd is instantiated. How to do that in Project where FileDialog is not a
member of Application?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top