Is there a way to open html page from vba directly in default browser? I don't want to create a form and use webbrowser or similar component.
The idea is open external browser and write page in it somehow...
To open a predefined URL in a named browser you can use VBScript like this:
Dim strURL: strURL="https://stackoverflow.com/questions/67530458/open-html-page-from-memory"
Dim iState:iState=3
Dim bWait:bWait=true
Set oWS=CreateObject("Wscript.Shell")
oWS.Run "chrome -url " & strURL,iState,bWait
oWS.Run "firefox -url " & strURL,iState,bWait
set oWS=nothing
If you omit the browser name it should invoke the default browser.
It is years since I used VBA but I'm fairly confident the approach is very similar in VBA.
Related
I'm new with VBS and I can't find how to interact (basic functions such as clic, write something) with a webpage after having load the URL in Edge.
Here is how I open my webpage for instance
dim objShell, strPath1, strAttr1, strAttr2
Set objShell = WScript.CreateObject("WScript.Shell")
strPath1 = """C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"""
strAttr1 = " -inprivate "
strAttr2 = " http://www.someWebPage.com/ "
objShell.Run strPath1 & strAttr1 & strAttr2
I've found many things like that :
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://www.somepage.com/"
With this object IE, it seems possible to modify forms, click here and there ... But it only worked with Internet Explorer.
I think I can manage to find the right HTLM piece of code that is useful (at least this is not what I'm looking for right now ^^ ).
Do you have any advise ?
Thanks a lot in advance
Microsoft Edge browser doesn't support the COM automation interface that used in VBS. If you want to automate Microsoft Edge, you should use WebDriver.
To get started using WebDriver, you will need to download a testing framework of your choice along with an appropriate language binding and the MicrosoftWebDriver server.
We usually use Selenium and you could download the language binding in this page. At the same time, you could download Microsof Edge WebDriver in this page.
Reference link:
Programmatically create Edge browser instance
Will Microsoft Edge support COM automation (InternetExplorer object)?
I have developed a simple application in VB.net that just opens a website, navigates to a certain link in that website and then depending on certain events navigates to another link.
Everything is working fine, except that when I grab the contents of the "href" tag, it seems truncated (for want of a better word). If I inspect the tag in chrome inspector the link is complete, but in my app it is not.
I am using the standard WebBrowser control in VB.Net. But I have tried the WebKit and Awesomium options as well. I must be missing something simple here. Any help would be appreciated thanks.
Below is the code I use to grab the "href" tag:
Dim div2 As HtmlElement = WebBrowser4.Document.GetElementById("ctr1")
'On Error Resume Next
For Each element As HtmlElement In div2.Document.Links
TextBox2.Text = "Navigating Web 3 Again " & element.GetAttribute("href") 'TextBox2.Text & element.GetAttribute("href") & vbCrLf
'element.InvokeMember("Click")
WebBrowser3.Navigate(element.GetAttribute("href"))
Exit For
Next
I'm a web developer but now I have to make a windows-based program using VB.net. I have two website domain A and B that B is shown in A using an ifram element. The code is like this:
<iframe scrolling="no" src="//B.com/newsgroup.php?id=4"></iframe>
B.com stands for my second domain.
I want to use Webbrowser control in VB.net to show my website A to my consumers. Now for some reasons I want to show ONLY the ifram which contains B contents and the important thing is that first website's domain shouldn't change.
I tried to use wb1.DocumentText = iFramCode but instead of showing ifram, I only get a ifram which the URI of SRC was written! So I think the best method is that I remove all of the code and only keep the iFram's code like cutting head and end of a cucumber!
What I have to do to only keep a specified piece of HTML by deleting other codes?
You can try
Dim iFrame = wb1.Document.Body.GetElementsByTagName("iframe")
Dim iFrameContents = iFrame.InnerText
Dim wb2 as New WebBrowser
wb2.Navigate(String.Empty)
wb2.Document.Write(iFrameContents)
currently i can accomplish this using IE
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Navigate "www.google.com"
ie.document.getElementByID("blah").value = "blah"
im curious if there is a way to navigate to website and fill out info using other than IE with VBA for example with FireFox or Chrome
i know how to navigate to other websites using any of the explorers for example Chrome as per below, but i would like to know how can fill out fields like search field on www.google.com using Chrome
call Shell("C:\Program Files\Google\Chrome\Application\chrome.exe"& " " & URL)
You can use this Selenium wrapper to drive Chrome or Firefox (or PhantomJS). Note that it is currently in beta. Once it is installed, either add a reference to Selenium Type Library or use late binding (example below).
In my (very) limited tests, the only noticeable difference is the couple seconds it takes to load the driver.
Here is a simple example from the link above (modified to use late binding) that fills out the search field in Google and clicks the search button:
Dim selDriver As Object
Set selDriver = CreateObject("Selenium.WebDriver")
selDriver.Start "chrome", "http://www.google.com/"
selDriver.Open "http://www.google.com"
selDriver.Type "name=q", "Eiffel Tower"
selDriver.Click "name=btnG"
selDriver.stop
As of 2016, the Selenium wrapper was moved to Github instead of the above Google address. Additionally, if you're using Chrome you'll want to update the web driver for Google Chrome here.
Selenium Basic
After downloading these items you'll then need to follow the instructions above for adding the library to in your Visual Basic Editor from within Excel. Afer doing so, you should be able fill out a web form using vba and chrome as originally requested.
I have a webpage that allows users to download excel reports, in Chrome, it just tries to download an aspx page instead of the excel like it successfully does in IE and Firefox.
Is this a known issue and is there a workaround?
I am using this in VB:
db.subRunReader(resultSQL)
dgProperties.DataSource = db.sqlReader
dgProperties.DataBind()
db.subCloseReader()
db.subCloseConnection()
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dgProperties.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
Response.Redirect(Request.Url.ToString())
Thanks.
Not sure about your specific situation, but in general whenever you want a file downloaded, it is a good idea to add a Content-Disposition header. In ASP.NET MVC it would be done like this:
Response.Headers["Content-Disposition"] =
"attachment;filename=yourfile.xls";
I expect in ASP.NET 2.0 it would be something similar. This tells the browser that it needs to download the file.