Skip to main content

Posts

Showing posts from December, 2017

VBA to read text from an already open webpage

VBA to read text from an already open webpage ' Determine if a specific instance of IE is already open.     Set objShell = CreateObject( "Shell.Application" )     IE_count = objShell.Windows.Count     For x = 0 To (IE_count - 1 )         On Error Resume Next     ' sometimes more web pages are counted than are open         my_url = objShell.Windows(x).Document.Location         my_title = objShell.Windows(x).Document.Title         'You can use my_title of my_url, whichever you want         If my_title Like "Put your webpage title here" & "*" Then    'identify the existing web page             Set ie = objShell.Windows(x)             Exit For         Else         End If     Next

Vba - close all instances of internet explorer

Vba - close all instances of internet explorer  Option Explicit Sub IE_Sledgehammer()     Dim objWMI As Object, objProcess As Object, objProcesses As Object     Set objWMI = GetObject("winmgmts://.")     Set objProcesses = objWMI.ExecQuery( _         "SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")     For Each objProcess In objProcesses         Call objProcess.Terminate     Next     Set objProcesses = Nothing: Set objWMI = Nothing End Sub

VBA UI Automation - Close All IE windows

Add below VBA references VBA UI Automation - Close All IE windows Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _ ByVal HWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Public Const WM_CLOSE As Long = &H10 Public Const IE_WINDOW_CLASS = "IEFrame" Sub CloseAllInternetExplorer() Dim HWnd As Long HWnd = FindWindow(IE_WINDOW_CLASS, vbNullString) Do Until HWnd = 0 SendMessage HWnd, WM_CLOSE, 0&, 0& HWnd = FindWindow(IE_WINDOW_CLASS, vbNullString) Loop End Sub

VBA - Web Automation - Part 1

VBA - Web Automation - Part 1 Sub YouTube()     Dim i As Long     Dim IE As Object     Dim objElement As Object     Dim objCollection As Object     ' Create InternetExplorer Object     Set IE = CreateObject("InternetExplorer.Application")     ' You can uncoment Next line To see form results     IE.Visible = True     ' Send the form data To URL As POST binary request     IE.Navigate "https://www.youtube.com/feed/trending"     ' Statusbar     Application.StatusBar = "www.excely.com is loading. Please wait..."     ' Wait while IE loading...     Do While IE.Busy         Application.Wait DateAdd("s", 1, Now)     Loop     ' Find 2 input tags:     '   1. Text field     '   <input type="text" class="textfield" name=&