?
Solved

Dialog to select a file for pdf viewing

Posted on 2013-01-24
3
Medium Priority
?
204 Views
Last Modified: 2013-01-24
excel 2010  vba

What I Have:
AcroPDF1

Combobox or listbox
Command Button

What i need:
Open a pdf file via  a selection:

I need to select a pdf file from a folder then select its sub folder.

Then press the command button to view the file in the AcroPDF1 object.

I have the code to present the file in the Adobe control.

Just looking for the code to select a pdf file to open..

Thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Shanan212 earned 2000 total points
ID: 38814844
Are you looking for the code for open dialog box? Then use below

Dim Filetoopen As String
Filetoopen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="PDF Files *.pdf (*.pdf),")

If Filetoopen = False Then
    MsgBox "No file specified!"
End If

Open in new window

0
 
LVL 3

Author Comment

by:fordraiders
ID: 38816485
Yes, Thayt would work...but executing the rest in code Like Below:
This works also:
 Dim ctlPDF As Control
    Dim strPath As String
    Dim SelectFile As String
    ' Set PDF control to reference new instance of class object.
    Set ctlPDF = Me.AcroPDF1

With Application.FileDialog(msoFileDialogOpen)
    .Title = "Select Pdf File Please"
    .AllowMultiSelect = False
    .Filters.Clear
   
    ' Add Filters to the bottom of dialog
    .Filters.Add "Pdf", "*.Pdf, 1"
    .InitialFileName = ""
    If .Show Then
        SelectFile = .SelectedItems(1)
    Else
    ' If the user selects cancel
        SelectFile = ""
    End If
End With

' more code
 ' First check if it is a PDF file.
    If Not Right$(SelectFile, 4) = ".pdf" Then
        Err.Raise vbObjectError + 1
    End If

    ' Next check if the file exists.
    If Len(Dir(SelectFile)) > 0 Then
        ' Display file in control.
        ctlPDF.src = SelectFile
    Else
        Err.Raise vbObjectError + 2
    End If
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 38816511
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question