Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dialog to select a file for pdf viewing

Posted on 2013-01-24
3
Medium Priority
?
205 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

604 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