Ok im lost...this should be working
When i run it it finishes but dosent create the image as an embeded object.. What am i doing wrong?? Please advice or Correct...
Code:
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 KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Sub Screen_Capture_VBA()
Dim Sec3 As Date, PasteYes As Integer
MsgBox "Three seconds after you click OK " & _
"the active window will be copied to the clipboard."
Sec3 = DateAdd("s", 2, Now)
Do Until Now > Sec3
DoEvents
Loop
' Run ScreenCapture Sub Routine
ScreenCapture
'------------------------------------
PasteYes = MsgBox("Click OK to paste the screen capture in VBA.", _
vbOKCancel)
If PasteYes = 1 Then
'Paste Image in Chart and Export it to Image file.
Charts.Add
ThisWorkbook.Charts(1).AutoScaling = True
ThisWorkbook.Charts(1).Paste
ThisWorkbook.Charts(1).Export Filename:="C:\ScreenCapture\ClipBoardToPic.jpg", FilterName:="jpg"
'Supress warning message and Delete the Chart
Application.DisplayAlerts = False
ThisWorkbook.Charts(1).Delete
Application.DisplayAlerts = True
'Attach the file to Excel
Attach_File
'----------------------------------
ThisWorkbook.Activate
ThisWorkbook.Sheets(1).Select
End If
End Sub
Sub ScreenCapture()
keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub
Sub Attach_File()
ActiveCell.Select
ActiveSheet.OLEObjects.Add(Filename:="C:\ScreenCapture\ClipBoardToPic.jpg", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _
"C:\Program Files\Internet Explorer\iexplore.exe", IconIndex:=10, IconLabel _
:="ClipBoardToPic.jpg").Select
End Sub
When i run it it finishes but dosent create the image as an embeded object.. What am i doing wrong?? Please advice or Correct...