Set Google Chrome Window to a Variable - excel

I'm trying to open a Google Chrome window, and continue to use that window to do many things. Which means I need to set it to a variable. Is there anyway to do this?
I have the following code to open the Google Chrome window and navigate to a URL, but I need to do more than that.
Sub Test()
Shell ("C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url https://google.ca")
End Sub
I want to type in my username and password, hit the submit button to log in, and do other things. Is there a way I can reference the chrome window like I could in Internet Explorer? (by using Set IE = ...)

Let us know exactly what you are trying to do in google chrome from excel.
If you are trying to send key commands you can try to use:
Shell ("C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url https://google.ca")
Application.Wait Now + 0.00003
Application.SendKeys "{Tab}", True
etc. etc. etc.
Hope this helps!

Related

How to fix Sendkey Alt Tab that is Not Working Anymore

I want to make some auto fill form from excel to web page. First I try to switch from Excel to web page by click Alt+Tab. I used this code Send Keys ("%{TAB}%"). It's work fine in that day, but when i will continue my program in next day, the code is not working anymore.
(Note
I don't use code
IE.navigate URL
from excel to access web page , because that page is child link and i don't know the address)
I work in excel 2010
I used this code
Application.SendKeys ("%{TAB}%")
How to fix that error or if any another code to switch from excel to webpage.
you need to use Alt+Tab to switch window, use this code, it works for me
Application.SendKeys "%{TAB}", True

How to open an 'incognito' window from Microsoft Excel?

I've created links to the web in Excel but I need to find a solution how to open an 'incognito' window in my 'default' Chrome browser.
I found a way to accomplish this. Create a desktop shortcut. In that shortcut have it direct to the browser. I did it with Chrome, so mine looked like:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Then after the link to the browser is done add the switch to open in Incognito (may differ for browser). For Chrome it is -incognito
You then add the link you want to open, placing it inside quotes.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -incognito "http://yourlinkhere.com"
In Excel you will link to the shortcut. It will give you warning boxes but those are easy enough to close. If anyone knows how to make a macro to disable them for just this click then I would like to know.
Below code works
Sub OpenIncognito()
Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -incognito -url https://google.com")
End Sub

Make IE a default browser using VBA

I want to write SubRoutine in Excel to make IE a default browser using VBA.
I have to run .bat file that will open Intranet url with random token parameter (from .bat file) with default browser. Some users may have Chrome as default browser but I want them to temporarily change to IE as my another SubRoutine require IE as a browser. I can change it back to chrome using VBA code.
I know that I can use shell to open IE with specified URL (even Chrome is set as default browser), but, as you may see, it will not solve my problem.
I expect to see code look like this
Set Shell = CreateObject("wscript.shell")
Shell.Run ("iexplore.exe --make-default-browser")

Open multiple hyperlinks in one window using Internet Explorer

I'm using the following code to open several Hyperlinks in multiple tabs from excel in one window:
Sub Open_Hyperlinks()
Range("C10:C17").Select
Dim hl as Hyperlink
On Error resume next
for Each hl in selection.Hyperlinks
hl.Follow
Next hl
End Sub
But I would like to include a specific instruction to open the hyperlinks using Internet Explorer and not the default browser setup in my terminal due to the fact that for administrator permissions I'm not able to change it.
Do you know how to include that instruction?
You could try by calling Internet Explorer directly:
Call Shell("C:\Program Files (x86)\Internet Explorer\iexplore.exe -url " & hl. Address ,vbMaximizedFocus)

Automatically closing an excel popup prompt using VBscript

I have an excel file that is supposed to access a remote monitoring server through a web query. Since the data in the file has to be periodically refreshed and saved, I have written a .vbs script to do it. It works fine, but since the server uses basic authentification security, which cannot be turned off, each time it runs, excel throws a popup "Windows Security" window asking for the username and password. There is an option to "Save credentials", but it still requires for the user to click "OK" to proceed, but the system requires there to be no user interaction.
Googling around I found this stack exchange post and other similar approaches, so I modified the script for my needs:
Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("Windows Security")
If ret = True Then
wshShell.SendKeys "{enter}"
Exit Do
End If
WScript.Sleep 500
Loop
The script does trigger when the window appears and even registers an "enter" keypress on whatever window I have focus at that time, but it cannot focus on the popup window itself. It works perfectly fine on other applications such as "Notepad" or "calculator". Is this somehow specific to popup windows? How can I modify the script to focus on the "Excel" popup? Are there other, simpler or more reliable alternatives?
Thanks
Unfortunately, AppActivate and SendKeys don't seem to always work so well on popup and dialog windows.
There is a command-line utility called nircmd that can do what you need, however. It's a great tool to have anyway and you'll probably find various other uses for it.
Download it and throw it in the same folder as your VBScript. Or, save it in your System32/SysWow64 folder or any other folder included in your %path% environmental variable. Then include the following statements in your VBScript:
With CreateObject("WScript.Shell")
.Run "nircmd dlg """" ""Windows Security"" click ok"
End With
The dlg command has the following arguments:
dlg [Process Name] [Window Title] [Action] [Parameters]
We'll leave [Process Name] blank ("""") and just supply the [Window Title]. Note that the quotes here are doubled because they're within a VBS string literal. For the final argument, you need to specify the control ID of the button you want to push/click. For typical dialog buttons (OK, Cancel, Yes, No, etc), you can try using nircmd's predefined control IDs: ok, cancel, yes, no, etc. Otherwise, you'll need to use a tool like Spy++ to determine the button's control ID and pass that instead.

Resources