Solved

Dialog to select a file for pdf viewing

Posted on 2013-01-24
3
195 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
First Blank Cell in a range 7 35
Split a string in excel 9 34
Pivot help - Display only Is Not Null 7 16
Excel range I cannot find 8 20
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now