AnilPullagura
Board Regular
- Joined
- Nov 19, 2010
- Messages
- 98
Hello All,
I am trying to create a macro that opens a website that is windows authenticated and click on a button named "Login" and then take a screen shot and paste it in a new word document.
I am getting the error, "Method Document of object iwebbrowser2 failed" and when I click on Debug and execute, the macro executes. I want to get rid of the error and have not been successful so far.
Please help me as where the code is incorrect.
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_SNAPSHOT = &H2C
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub PrintScreen()
Dim IE As Object
Dim elems As Object
Dim e As Variant
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://example.com/"
With IE.document
Set objCollection = IE.document.getElementsByTagName("input")
Set elems = .getElementsByTagName("input")
For Each e In elems
If (e.getAttribute("value") = "Login") Then
e.Click
Exit For
End If
Next e
End With
keybd_event VK_SNAPSHOT, 1, 0, 0
Dim MW As Object
Set MW = CreateObject("Word.Application")
MW.Visible = True
MW.Activate
MW.Documents.Add
'MW.WindowState = wdWindowStateMaximize
MW.Selection.Paste
'keybd_event VK_SNAPSHOT, 1, 0, 0
'Activeword.Paste
End Sub
Thanks,
Anil
I am trying to create a macro that opens a website that is windows authenticated and click on a button named "Login" and then take a screen shot and paste it in a new word document.
I am getting the error, "Method Document of object iwebbrowser2 failed" and when I click on Debug and execute, the macro executes. I want to get rid of the error and have not been successful so far.
Please help me as where the code is incorrect.
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_SNAPSHOT = &H2C
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub PrintScreen()
Dim IE As Object
Dim elems As Object
Dim e As Variant
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://example.com/"
With IE.document
Set objCollection = IE.document.getElementsByTagName("input")
Set elems = .getElementsByTagName("input")
For Each e In elems
If (e.getAttribute("value") = "Login") Then
e.Click
Exit For
End If
Next e
End With
keybd_event VK_SNAPSHOT, 1, 0, 0
Dim MW As Object
Set MW = CreateObject("Word.Application")
MW.Visible = True
MW.Activate
MW.Documents.Add
'MW.WindowState = wdWindowStateMaximize
MW.Selection.Paste
'keybd_event VK_SNAPSHOT, 1, 0, 0
'Activeword.Paste
End Sub
Thanks,
Anil