0

I am trying to convert the PDF file to excel via online converter. To do that I need to upload the file through browser button so I created a code till clicking on the button however I am not able to choose the file from dialog box.

Please help me in below code.

Sub autoIE()

Dim ie As Object
Dim Hdoc As HTMLDocument
Worksheets("Sheet6").Activate
Range("B1").Copy
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "https://www.pdftoexcelconverter.net/"
ie.Visible = True
While ie.Busy
DoEvents
Wend

Set Hdoc = ie.document
Hdoc.all("Filedata").Click

Hdoc.Value = ("C:\Users\kiranm\Desktop\2019\11.pdf")

End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
kiran mamalwad
  • 159
  • 1
  • 11
  • You need to use `FindWindow`, `FinwindowEx` API to put the filename in that dialog box and then you will need `SendMessage` API to click on the `Open` button – Siddharth Rout Dec 11 '19 at 11:02
  • I had written an blog about this 7 years ago. Now it is not available on my website. To view the old content you may want to see [THIS](http://oldweb.today/firefox/20031211111047/http://www.siddharthrout.com/2012/02/02/vbavb-netvb6click-opensavecancel-button-on-ie-download-window-part-ii/) That example shows how the file save as name is entered in the dialog box and the save button is clicked. You have to follow the same logic. – Siddharth Rout Dec 11 '19 at 11:14
  • @SiddharthRout Unfortunately, Microsoft messed up the handles for the Buttons when they released IE11, so `FindWindowEX` can no longer identify them. You're stuck using `SendKeys` instead if you want to do this. – Chronocidal Dec 11 '19 at 11:29
  • I don't want to use the SendKeys as it is not reliable, you said Microsoft messed up the handles for this, so is it possible is we use different browser? – kiran mamalwad Dec 11 '19 at 11:40
  • For other browsers you must use Selenium because they have no COM API. One alternate is to use Word to open the pdfs and overtake the needed information to Excel. Word converts pdfs to editable text. – Zwenn Dec 11 '19 at 12:02
  • @Chronocidal: It still works. Just tested it :) – Siddharth Rout Dec 11 '19 at 12:18
  • @Zwenn: The PDF file is not editable it is a scan image so we can not convert it through the word file. – kiran mamalwad Dec 11 '19 at 12:23
  • @SiddharthRout: could you please attach the code which you tested now, may be it can be helpful for me as I am not able to link which you have provided above. – kiran mamalwad Dec 11 '19 at 12:25
  • It is the same code from the above link, Can you please give it a try? And if you do not succeed then post the code that you tried and I will post the complete code here with explanation. That is a promise :) – Siddharth Rout Dec 11 '19 at 12:31
  • @SiddharthRout: The page is still loading, hence I am not able to read it:) – kiran mamalwad Dec 11 '19 at 12:34
  • can anyone please help me on this? – kiran mamalwad Dec 11 '19 at 12:38
  • See [THIS](https://stackoverflow.com/questions/16174469/unprotect-vbproject-from-vb-code/16176557#16176557) It works on the same principle... – Siddharth Rout Dec 11 '19 at 14:07
  • SendKeys with selenium is reliable. I used [here](https://stackoverflow.com/a/52906215/6241235) 64 bit versions of with SendMessageW and FindWindowExW – QHarr Dec 11 '19 at 15:11
  • Ok, there is no need to click the save button. The button 'Free Download' includes an a tag with the link to the converted file. You can download it with the URLDownloadToFile function. – Zwenn Dec 11 '19 at 15:55
  • @Zwenn This is to download the converted file but the question is how to upload it. – kiran mamalwad Dec 16 '19 at 11:34

0 Answers0