locked
How can I open Password protected PDF file using excel VBA? RRS feed

  • Question

  • Hi Team,

    I am trying to open password protected PDF file(I know the password) using file using below code, but i am not able to give password through VBA by send key method. kindly help to get it resolved.

    Function OpenAnyFile(strPath As String)
      Set objShell = CreateObject("Shell.Application")
      objShell.Open (strPath)
      SendKeys "OOps!123@"
    End Function

    Sub Test()
      Dim pdfPath As String
      pdfPath = Application.GetOpenFilename(filefilter:="PDF file (*.pdf), *.pdf")
      Call OpenAnyFile(pdfPath)
    End Sub


    Tuesday, February 2, 2016 10:57 AM

Answers

  • Hi Sachinvaidya,

    As far as I know, excel object model don’t provide the way to open pdf file. With word 2013 we could open the pdf file, and the Documents.Open method has the parameters to specify the password, you could try it in excel. (add word object model reference)

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 3, 2016 6:53 AM

All replies

  • Hi Sachinvaidya,

    As far as I know, excel object model don’t provide the way to open pdf file. With word 2013 we could open the pdf file, and the Documents.Open method has the parameters to specify the password, you could try it in excel. (add word object model reference)

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 3, 2016 6:53 AM
  • Nope, unfortunately this is not an answer. I have tested it and it simply does not work. PasswordDocument, PasswordTemplate, WritePasswordDocument, and WritePasswordTemplate parameters in Documents.Open() method is simply used for opening Word file (*.doc, *.docx) not for PDF file.
    Tuesday, October 24, 2017 11:23 AM