View Single Post
 
Old 05-25-2021, 05:21 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code isn't telling the file to open, it is just returning the name of the selected files. If you want to open it then you need to have a line of code that does that. The question is, how do you want to open it - in Word as an editable file vs in the default Acrobat viewer (like Reader or Edge). Based on your earlier post, I assume you want the viewer option - the easiest way is therefore to follow a hyperlink to the filepath.
Code:
Public Sub DirPathNamesWithFilePicker()
  Dim xFD As FileDialog, xFdItem As Variant
  Set xFD = Application.FileDialog(msoFileDialogFilePicker)
  With xFD
    .Title = "Select a file"
    .Filters.Clear
    .Filters.Add "Acrobat Files", "*.PDF", 1
     If .Show = -1 Then
        For Each xFdItem In .SelectedItems
          Debug.Print "Path Name: " & xFdItem
          ActiveDocument.FollowHyperlink xFdItem
        Next xFdItem
     End If
   End With
  Set xFD = Nothing
End Sub
If you are using the userform, you might prefer to delay opening the PDF until you close the userform. In that case, write the value to a control on the userform instead so it can be used when ready.

I would be surprised if LoadPicture works on a PDF. I would expect that it would want a graphic file (like a bmp or jpg)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote