I am trying to search some value from excel and paste the capscreen to a word file. It work fine when there is only one item to search.
But I wonder if it is possible to search through a list and paste them all in to a word file.
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Const VK_SNAPSHOT As Byte = 44
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_SHOWMAXIMIZED = 3
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_V = &H56
Private Const KEYEVENTF_KEYUP = &H2
Sub Sample()
Dim IE As Object
Dim hwnd As Long
IECaption As String
Dim workRng As Range
Dim searchword As String
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "www.Google.com"
Sleep 5000
IECaption = "Google - Internet Explorer"
hwnd = FindWindow(vbNullString, IECaption)
ShowWindow hwnd, SW_SHOWMAXIMIZED
Sleep 1000
DoEvents
I tried to make a loop for the code below but it seems that it could only search for A1 A2, or totally not working. Even if it managed to search A2 it still cannot paste the screen shot to word.
Set workRng = Range("A1:A10")
For Each searchword in workRng
IE.Document.All("q") = searchword.Value
IE.Document.All("btnK").Click
Sleep 1000
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
Set wordobj = CreateObject("Word.Application")
Set objDoc = wordobj.Documents.Add
wordobj.Visible = True
Set objSelection = wordobj.Selection
objSelection.Paste
Next searchword
End Sub