Hello Again,
I have adopted below code which I have found on the web but it is not working.
What I am doing here is trying to do here is searching specific or part of file name of a PDF and open.
Uptill searching is working but it is not opening the PDF file.
Below is the script. any help is appreciated.
I have adopted below code which I have found on the web but it is not working.
What I am doing here is trying to do here is searching specific or part of file name of a PDF and open.
Uptill searching is working but it is not opening the PDF file.
Below is the script. any help is appreciated.
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2
'************************************************************************************************************************
Sub openfile()
Dim strpath As String
Dim openfile As Variant
Dim FileToDiag As FileDialog
Dim fileSelected, RunBookCrtF
ChDrive "C:\"
ChDir Range("E1").Value '"C:\testing\" 'change to your own folder name
openfile = Application.GetOpenFilename(Title:="File to open", _
InitialFileName:=Range("E1").Value & Application.PathSeparator & "*" & Range("E3").Value & "*.PDF", _
FileFilter:="PDF Files *.pdf (*.pdf),")
Set openfile = Application.FileDialog(msoFileDialogOpen) 'Application.FileDialog(msoFileDialogFilePicker)
With openfile
.AllowMultiSelect = False
.InitialFileName = Range("E1").Value & Application.PathSeparator & "*" & Range("E3").Value & "*.PDF"
.ButtonName = "Open Selection"
.Title = "Select PDF File To Open"
.Filters.Add "...", "*.pdf (*.pdf)", 1
.Show
For Each fileSelected In .SelectedItems
RunBookCrtF = fileSelected
Next
End With
If openfile = False Then
MsgBox "No file specified.", vbExclamation, "Bamm!"
Exit Sub
Else
End If
ShellExecute Application.hwnd, "open", openfile, vbNullString, "C:\", SW_SHOWMAXIMIZED 'SW_SHOWNORMAL
End Sub