Solved

Dialog to select a file for pdf viewing

Posted on 2013-01-24
3
197 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
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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…

786 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