0

I'm trying to use MS Project 2013 to open a filechooser box, select a .pptx file, and open it.

If I write down the filepath inside VBA, my code opens the pptx without any problem and do what it has to do.

My problem is that somehow I can't use the msoFileDialogFilePicker object. I've set my references to use MS Word Object Library, Visual basic for Applicaitons, and even Excel Object, but the Application object doesnt recognize it no matter what reference I choose.

I've also tried getOpenFilename method, but the application doesnt recognize it either.

Heres my code so far:

Dim strTemplatePPT As String
strTemplatePPT = Application.GetOpenFilename("Modelos de PowerPoint,*.pptx*", 1, "Abrir Arquivo", , False)

Set ppAppl = CreateObject("PowerPoint.Application")
ppAppl.Visible = True
Set ppPres = ppAppl.Presentations.Open(strTemplatePPT, msoFalse)

Have anyone had this problem?

Thanks.

  • How are you trying to call `FileDialog()`? Project doesn't appear to support this method, but you should be able to invoke it on your `ppAppl` object. – jsheeran Aug 26 '16 at 15:06
  • maybe you can benefit form [this post](http://stackoverflow.com/questions/9476268/filedialog-doesnt-work) – user3598756 Aug 26 '16 at 15:38

1 Answers1

1

As jsheeran said, It is possible to use the FileDialog() method inside the ppAppl object, as follows:

Dim strTemplatePPT As String
Dim ptr_fileDialog As FileDialog

Set ppAppl = CreateObject("PowerPoint.Application")

Set ptr_fileDialog = ppAppl.FileDialog(msoFileDialogFilePicker)
ptr_fileDialog.Title = "Escolha o arquivo de Template"
ptr_fileDialog.Filters.Clear
ptr_fileDialog.Filters.Add "Arquivo Powerpoint", "*.pptx"
ptr_fileDialog.Show
strTemplatePPT = ptr_fileDialog.SelectedItems(1)

If (strTemplatePPT = "-1") Then Exit Sub

ppAppl.Visible = True
Set ppPres = ppAppl.Presentations.Open(strTemplatePPT, msoFalse)

Even though Project isn't opening the fileDialog by itself, I can use the powerpoint instance to send the results back to Project, because I'll use powerpoint anyway for the rest of my code.

Thanks a lot for the info man :)