Chúng ta gặp rắc rối khi mà màn hình cứ bị excel chèn vào khi chụp ảnh. Sau một hồi tìm kiếm vất vả, cuối cùng mình cũng kiếm được đoạn code để chụp ảnh màn hình và xuất ra trên máy tính.
Nguồn:
Mã:
'Declare Windows API Functions
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'Declare Virtual Key Codes
Private Const VK_SNAPSHOT = &H2C
Private Const VK_KEYUP = &H2
Private Const VK_MENU = &H12
Public Const VK_TAB = &H9
Public Const VK_ENTER = &HD
Sub ScreenPrint() ' <= chay chuong trinh nay de chup anh
'Press Alt + TAB Keys -- Step1
Alt_Tab
'Press Print Screen key using Windows API -- Step2.
keybd_event VK_SNAPSHOT, 1, 0, 0 'Print Screen key down
keybd_event VK_SNAPSHOT, 1, VK_KEYUP, 0 'Print key Up - Screenshot to Clipboard
'Paste Image in Chart and Export it to Image file. -- Step3
Charts.Add
ThisWorkbook.Charts(1).AutoScaling = True
ThisWorkbook.Charts(1).Paste
ThisWorkbook.Charts(1).Export Filename:="E:\ClipBoardToPic.jpg", FilterName:="jpg" ' Image se duoc luu o trong o E. Ban co the sua link tuy y.
'Supress warning message and Delete the Chart
Application.DisplayAlerts = False
ThisWorkbook.Charts(1).Delete
Application.DisplayAlerts = True
End Sub
Sub Alt_Tab()
DoEvents
keybd_event VK_MENU, 1, 0, 0 'Alt key down
DoEvents
keybd_event VK_TAB, 0, 0, 0 'Tab key down
DoEvents
keybd_event VK_TAB, 1, VK_KEYUP, 0 'Tab key up
DoEvents
keybd_event VK_ENTER, 1, 0, 0 'Tab key down
DoEvents
keybd_event VK_ENTER, 1, VK_KEYUP, 0 'Tab key up
DoEvents
keybd_event VK_MENU, 1, VK_KEYUP, 0 'Alt key up
DoEvents
End Sub
Bạn cần đăng nhập để thấy link