Open File

Michaels41

Registered User.
Local time
Today, 13:44
Joined
Feb 24, 2012
Messages
18
I'm trying to open a powerpoint presentation from within my access application. I can get the dialog box to open perfectly, however, when I select a file to open, nothing happens. Here is the code:

Public Function OpenFile() As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Select Presentation"
.ButtonName = "Open"
.Filters.Clear
.Filters.Add "PowerPoint", "*.ppt"

'Set initial path
.InitialFileName = "P:\Safety\2012 NA Monthly Awareness Presentations\"
.InitialView = msoFileDialogViewPreview

'Show the dialog and test the return
If .Show = 0 Then
Exit Function
End If

OpenFile = Trim(.SelectedItems(1))

End With

End Function

Thanks in advance for your help.

Mike
 
There is nothing shown here that opens anything. The function returns the picked file name and that's it.
 
OK....with that said, how do I get the file to open?
 
how do I get the file to open?

Depends on what "open" means in your context.

1) Open the file in which ever program is configured to handle the file extension in Windows.
2) Open the file and read the file contents into a VBA variable.
etc...
 
I use the FollowHyperlink Method. It works to open any file with a registered extension.
 
Thanks for your help. I actually found the answer in a google search. simply had to add a few lines of code to "open the powerpoint presentation". The code is:

Code:
Public Function OpenFile() As String
    Dim PPT As PowerPoint.Application
    Set PPT = New PowerPoint.Application
    
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Title = "Select Presentation"
        .ButtonName = "Open"
        .Filters.Clear
        .Filters.Add "PowerPoint", "*.ppt"
        
        'Set initial path
        .InitialFileName = "P:\Safety\2012 NA Monthly Awareness Presentations\"
        .InitialView = msoFileDialogViewPreview
        
        'Show the dialog and test the return
        If .Show = 0 Then
            Exit Function
        End If
        
        OpenFile = Trim(.SelectedItems(1))
                       
    End With
    
    PPT.Visible = True
    PPT.Presentations.Open FileName:=OpenFile
            
End Function

Thanks again for your help.

Mike
 
Congrats.

Some ppl use this forum as a crutch (the ones that cannot figure out Google, in this century!!!) and some for inspiration.

Come back when you have questions you cannot resolve yourself (by Googling or by the sometimes not obvious Access logic)
 
Try with this function:

Code:
Public Function OpenFile(Optional InitialFileName As String) As Boolean
    Const msoFileDialogFilePicker = 3
    Const msoFileDialogViewPreview = 4
 
    'if InitalFileName is a exists file,open it
    If Dir(InitialFileName) <> "" Then
        Shell "explorer """ & InitialFileName & """", vbNormalFocus
        OpenFile = True
    End If
 
    'else use a file dialog to select the file to open
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Title = "Select Presentation"
        .ButtonName = "Open"
        .Filters.Clear
        .Filters.Add "PowerPoint", "*.ppt"
        .Filters.Add "All File", "*.*"
        .FilterIndex = 1
        .InitialFileName = InitialFileName
        .InitialView = msoFileDialogViewPreview
        If .Show Then
            Shell "explorer """ & .SelectedItems(1) & """", vbNormalFocus
            OpenFile = True
        End If
    End With
End Function
 
Thanks for your help, spikepl. I always use google first to try to find code samples that I can adapt to my particular application. My first post included code that I copied and pasted into my app. However, I didn't fully understand the code and what the end result would be. Sometimes, the comments that are posted will trigger something or make the light come on. The extra lines of code I actually found in an Excel forum from another google search. As luck would have it, it worked fine in access as well.

Thanks again for all you do to support novice programmers like me.

Mike
 

Users who are viewing this thread

Back
Top Bottom