Solved

Dialog to select a file for pdf viewing

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

707 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

15 Experts available now in Live!

Get 1:1 Help Now