+ Reply to Thread
Results 1 to 1 of 1

VBA opening IExpl and taking screenshot fails to paste it in Excel Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2017
    Location
    Copenhagen
    MS-Off Ver
    Microsoft 2013
    Posts
    1

    VBA opening IExpl and taking screenshot fails to paste it in Excel Sheet

    I have this Macro that fails on the last row by saying: PasteSpecial Method of Range Class failed - Rune time 1004.

    1. Anyone can help me make it work?
    2. Is it possible to save the screenchot as an attachment on this sheet that I can double click it if I need to see the screenshot?

    Thank you all!

    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 = 2
    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
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
        IE.Navigate "www.google.com"
        Sleep 5000
        '~~> Get the caption of IE
        IECaption = "Google - Internet Explorer"
    
        '~~> Get handle of IE
        hwnd = FindWindow(vbNullString, IECaption)
    
        If hwnd = 0 Then
            MsgBox "IE Window Not found!"
            Exit Sub
        Else
            '~~> Maximize IE
            ShowWindow hwnd, SW_SHOWMAXIMIZED
        End If
    
    '--Pause
    Sleep 1000
        
        DoEvents
        '~~> Take a snapshot
        Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    
        '~~> Start Word
        Workbooks("Save PDF.xlsm").Activate
        Range("A1").Select
        Selection.PasteSpecial
        
    End Sub
    Last edited by Leith Ross; 01-14-2017 at 05:47 PM. Reason: Added Code Tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to grab screenshot and paste into the single or active worksheet
    By happyhardik in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-01-2022, 01:08 AM
  2. Screenshot a particular range in Excel and paste as a bitmap
    By BadAtExcl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2016, 03:18 PM
  3. Macro to Screenshot Excel and Paste Image to MS Word
    By ramlineses in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2016, 05:26 PM
  4. Using VBA for taking screen shots from PDF file and paste to excel
    By dontbugme1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2015, 11:48 AM
  5. Taking a image in out look email and paste into excel
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-14-2015, 11:19 AM
  6. [SOLVED] Paste Excel Userform Screenshot into Word document
    By t0mps in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2014, 07:10 AM
  7. Paste special comments macro fails in Excel 2010
    By kreutz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2013, 12:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1