• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

open pdf file held on textbox value

Abdullah

New Member
Dear friends thank you for the great CHANDOO ,,,

please help me about this macro

i have a search userform calling the data from an excel sheet and i have a command button in that user form i want it to open a pdf file which saved in a specific file according to the value shown in a textbox .
i attached a photo so please i want to click on ( open the file ) and will open the pdf file as the name is shown in ( number ) value in my example is ( 11 ) which is saved in a testfile .

hope you got my point .
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    75.2 KB · Views: 22
Abdullah

Firstly welcome to the Chandoo.org Forums

Try the following code:

Code:
Dim PDFDir As String, FName As String, PDFFile As String
Dim READERPath As String

FName = Textbox1.Text 'Change to suit your text boxes name
PDF_Dir = "C:\Users\Huis\Desktop\" 'Change to suit
PDFFile = PDF_Dir & FName

READERPath = "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe" 'Change to suit

Shell READERPath & " " & PDFFile, vbNormalFocus

Note the three lines that you need to change
 
Dear Hui
first of all i want to thank you for you reply
i used the code and i made the needed change and when i click on open the file it opened my adobe reader and give me a message ( there was an error opening the document . this file cannot be found )
and i'm sure that the file is in the correct folder .

and i send you an attachment
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    160.7 KB · Views: 14
Dear Hui
i'm just curious about this Quotation mark i made it in red , i have to leave it empty or not ?

and here is my code

Private Sub CommandButton4_Click()
Dim PDFDir As String, FName As String, PDFFile As String
Dim READERPath As String

FName = TextBox2.Text 'Change to ' suit your text boxes name
PDF_Dir = "C:\Users\Acer\Desktop\package calculation\" 'Change to suit
PDFFile = PDF_Dir & FName

READERPath = "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe" 'Change to suit

Shell READERPath & " " & PDFFile, vbNormalFocus
End Sub
 
Yes
Those Red " 's are a space between the program name and file name

Does Textbox2 contain the entire file name eg myfile140528.pdf or just the myfile140528 part?

Can you post the whole file or email it to me ?
 
i put 3 Attachment
one is the excel file and the others is the PDF which i want to open it in the search form .

thank you again and i'm so sorry for disturbance .
when you click the Search botton in the Excel file a user form will open you have to choose one of the OptionButton and write any letter in the text box 1 .

i spoke too much and i'm sure you know what you have to do sorry .
 

Attachments

  • 14.pdf
    95.4 KB · Views: 10
  • 15.pdf
    105 KB · Views: 12
  • package calculation.xlsm
    226.2 KB · Views: 15
In the Private Sub CommandButton4_Click() subroutine

Change the line:
Code:
FName = TextBox2.Text 'Change to suit your text boxes name
To:
Code:
FName = TextBox2.Text+".pdf" 'Change to suit your text boxes name
 
boss still i'm facing the same bproblem ( there was an error opening the document , this file cannot be found )

and this is my
Code:
Private Sub CommandButton4_Click()
Dim PDFDir As String, FName As String, PDFFile As String
Dim READERPath As String

FName = TextBox2.Text + ".pdf" 'Change to suit your text boxes name
PDF_Dir = "C:\Users\Acer\Desktop\package calculation\" 'Change to suit
PDFFile = PDF_Dir & FName

READERPath = "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe" 'Change to suit

Shell READERPath & " " & PDFFile, vbNormalFocus
End Sub
 
dear Hui

please just read thismaybe it help :

in my workbook there is a botton ( save as ) when you click this botton the page it save with PDF format and it open the pdf file without any problems .
 
Are your PDF files in: C:\Users\Acer\Desktop\package calculation\
Is your acrobat reader in : C:\Program Files\Adobe\Reader 11.0\Reader\

If you copy the following into the Address Bar of an Explorer Window
C:\Program Files\Adobe\Reader 11.0\Reader\15.pdf
What happens ?
 
Thats is due to the OpenAfterPublish:=True
part of the Built in ExportAsFixedFormat part of Excel
Its not related to what your trying to do, except that it shows that the file is in the correct location
 
my PDF Files is in C:\Users\Acer\Desktop\package calculation .

and when i copy this to my address bar C:\Program Files\Adobe\Reader 11.0\Reader\15.pdf
it give me error msg ( windows can't find C:\Program Files\Adobe\Reader 11.0\Reader\15.pdf . check the spelling and try again )
and here is a photo for the acrobat reader path .

i'm sorry to disturb you a lot
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    169 KB · Views: 8
i'm sure about my PDF files is in correct location but i'm little doubt about the path of my acrobat reader path .
 
My mistake

Copy the following into the address bar of Explorer:
C:\Program Files\Adobe\Reader 11.0\Reader\acrord32.exe C:\Users\Acer\Desktop\package calculation\15.pdf
 
Also check what the extension of the 15.pdf is as it may be something else, like 15 without an extension
 
boss
when i copy C:\Program Files\Adobe\Reader 11.0\Reader\acrord32.exe it's open a PDF Application .
and when i copy C:\Users\Acer\Desktop\package calculation\15.pdf to the address bar it's open the file ( 15 ) .
it's mean correct .
 
Can you try the following code:
Code:
Private Sub CommandButton4_Click()
Dim PDFDir As String, FName As String, PDFFile As String
Dim READERPath As String

FName = TextBox2.Text + ".pdf" 'Change to suit your text boxes name
PDF_Dir = "C:\Users\Acer\Desktop\package calculation\" 'Change to suit
PDFFile = Chr(34) + PDF_Dir + FName + Chr(34)

READERPath = "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe" 'Change to suit

Shell READERPath + " " + PDFFile, vbNormalFocus
End Sub
 
If that doesn't work try changing the line
Code:
FName = TextBox2.Text + ".pdf" 'Change to suit your text boxes name

to
Code:
FName = TextBox2.Text  'Change to suit your text boxes name
 
I dont know if this is relevant or not but I changed the PDF_DIR to PDFDIR in the following line to get it to work for me. Ialso had to add .pdf to the file name or it couldnt find it.
PDF_Dir = "C:\Users\Acer\Desktop\package calculation\" 'Change to suit
 
Last edited:
yes Mr. Hui ,,,,,,
it's great now
i want to thank you for the great help and to apology for my disturbance .
it's working properly .
 
Back
Top