Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2024, 06:53 AM
Tee Tee is offline Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Windows 10 Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Office 2021
Novice
Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox
 
Join Date: Dec 2024
Posts: 3
Tee is on a distinguished road
Default Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox

Hello Everyone.

I hope this post finds everyone to be in high sprits.



Upon searching the highs and lows of internet I have found this forum and I am hoping that someone will be able to help me with my predicament.

First of all I must clarify that I am not using Office 2021. I am using Office365 paid subscription which is not on the list when registering here.

I have a long word document which I edited after watching some YT videos and added bookmarks on the desired locations on the document. Document is saved as Macro enabled file. I made a simple user form in VBA, watched some more YT videos and after some trial and error I managed to submit the data in correct bookmark positions successfully.

The userform is inside a tab (two pages) first page is the form/bookmark fields and the other page is where there is a ListBox and a WebBrowser. ListBox (after even some more YT videos) shows the correct files (PDF format only files) from the desired location.

The predicament is that I need the PDF shown in the WebBroswer which is under the ListBox on tab page 2 and I cannot find anywhere and I have looked and looked for a solution for this.

When the user form loads up the ListBox is initialised and populates it with all the PDF files in that particular folder.

I would really appreicate if anyone can help me with the code on how a PDF will be shown in WebBrowser control if it is clicked.

This is the only functionality missing from the user form which is preventing it from being actually used.

I can post the existing code if it is needed. The ListBox is lablled as ListBox1 and WebBrowser as WebBrowser1.

Your help is highly appreciated.
Reply With Quote
  #2  
Old 12-17-2024, 05:42 PM
macropod's Avatar
macropod macropod is offline Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Windows 10 Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To do that, you would first have to automate your web browser, then open the PDF from there.

To automate Edge through VBA, you need to use SeleniumBasic. SeleniumBasic is a browser automation framework for VB.Net, VBA and VBScript. See:
EDGE : Opening and filling a webpage through VBA - Microsoft Q&A. The information there is a bit dated, but it should get you started in the right direction.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-20-2024, 12:03 AM
Tee Tee is offline Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Windows 10 Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Office 2021
Novice
Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox
 
Join Date: Dec 2024
Posts: 3
Tee is on a distinguished road
Default

Hello and thank you macropod for your reply.

Perhaps I was not able to explain clearly. I don't need the PDF to be displayed in MS Edge browser but the control of VBA Word form which is also called WebBroswer in that the PDF should be displayed when the selection is made from the ListBox.

I have seen some YT videos some time ago but for the life of me I cannot find them but predominately most YT videos are for MS Excel and not Word VBA.

Any idea how can I have the PDF displayed without opening external browser and only use the UserForm to display it?

Your help is much appreciated.

-Tee



Quote:
Originally Posted by macropod View Post
To do that, you would first have to automate your web browser, then open the PDF from there.

To automate Edge through VBA, you need to use SeleniumBasic. SeleniumBasic is a browser automation framework for VB.Net, VBA and VBScript. See:
EDGE : Opening and filling a webpage through VBA - Microsoft Q&A. The information there is a bit dated, but it should get you started in the right direction.
Attached Images
File Type: png Screenshot 2024-12-20 070052.png (142.6 KB, 14 views)
Reply With Quote
  #4  
Old 12-20-2024, 06:19 AM
hungt hungt is offline Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Windows XP Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Office 2010
Banned
 
Join Date: Jan 2020
Posts: 2
hungt is on a distinguished road
Default

Private Sub CommandButton1_Click()
Dim filename As String
' filename = "d:\myPDF.pdf" ' file path
filename = ListBox1.List(ListBox1.ListIndex) ' selected item in ListBox1
WebBrowser1.Navigate filename
End Sub
Reply With Quote
  #5  
Old 12-21-2024, 04:32 AM
Tee Tee is offline Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Windows 10 Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Office 2021
Novice
Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox
 
Join Date: Dec 2024
Posts: 3
Tee is on a distinguished road
Default

Thank you hungt for the code. I tried but it did not work. The webbroswer1 open google search with the file name and some javascript error comes up.

The below code is in Userform initialise section:

Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "C:\Users\Tee\Downloads"
MyFile = Dir(MyFolder & "\*.pdf")
Do While MyFile <> ""
ListBox1.AddItem MyFile
MyFile = Dir
Loop

I removed it and the code which you provided still didn't worked. I changed the folder location etc correctly.

Any idea what could be wrong or missing?

I appreciate your help.

Thank you.


Quote:
Originally Posted by hungt View Post
Private Sub CommandButton1_Click()
Dim filename As String
' filename = "d:\myPDF.pdf" ' file path
filename = ListBox1.List(ListBox1.ListIndex) ' selected item in ListBox1
WebBrowser1.Navigate filename
End Sub
Reply With Quote
  #6  
Old 12-21-2024, 06:01 AM
hungt hungt is offline Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Windows XP Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Office 2010
Banned
 
Join Date: Jan 2020
Posts: 2
hungt is on a distinguished road
Default

In UserForm


Option Explicit

Private Sub CommandButton1_Click()
Dim filename As String
' change "d:\sample.pdf" to the name of an existing file, np. "C:\Users\Tee\Downloads\XYZ.pdf"
filename = "d:\sample.pdf"
WebBrowser1.Navigate filename
MsgBox "Done"
End Sub

Private Sub CommandButton2_Click()
Dim filename As String
' first select - select one item in ListBox1, only then click CommandButton2
filename = ListBox1.List(ListBox1.ListIndex) ' selected item in ListBox1
WebBrowser1.Navigate filename
End Sub

Private Sub UserForm_Initialize()
'Dim MyFolder As String
'Dim MyFile As String
'Dim j As Integer
' MyFolder = "C:\Users\Tee\Downloads"
' MyFile = Dir(MyFolder & "\*.pdf")
' Do While MyFile <> ""
' ListBox1.AddItem MyFile
' MyFile = Dir
' Loop
End Sub
Reply With Quote
Reply

Tags
ms word vba, pdf in webbrowser control, word user form



Similar Threads
Thread Thread Starter Forum Replies Last Post
Toggling control checkboxes to true when a value in a control drop down is selected ccamm Word VBA 4 03-16-2024 06:44 AM
MsgBox launch when a Check Box Content Control is clicked wolfgrrl Word VBA 1 06-21-2019 12:13 PM
Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Moving Selected Items from a Multiselect Listbox on a userform to a bookmark in Word marksm33 Word VBA 3 01-15-2015 07:55 PM
Display a PDF in MS Webbrowser control when PDF is selected (clicked) from a ListBox Getting mult resps. selected in listbox to concatenate & paste at a bookmark in Word marksm33 Word VBA 3 01-15-2015 05:59 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft