如何截取应用程序的屏幕截图并使用 VBA 将其保存为文字
How to take screenshot of application and save it word using VBA
我有一个 VBA 代码可以打开 Attachmate Reflection(IBM Screen)。我想截取 window(如打印屏幕)的完整屏幕截图并将屏幕截图粘贴到 word 文档中。
但是,我无法截取打印屏幕并将其粘贴到 word 中。
为 objWord.Paste 行
获取“对象 属性 或方法不受支持”
'Reflection screen part
Set view = frame.CreateView(terminal)
Set screen = terminal.screen
...
' word document
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
Set para = objDoc.Paragraphs.Add
para.Range.Text = Inp_Str & vbCrLf & vbCrLf & vbCrLf
para.Range.ParagraphFormat.SpaceAfter = 10
objDoc.Paragraphs.Add
objDoc.Paragraphs.Add.Range.Text = "Line 2 hello"
**Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
'Paste into Word This paste is not working
objWord.Paste**
'quit the word application:
objWord.Quit
objWord.Paste
应更改为 objWord.Selection.Paste
。我还需要 Sleep
给 keybd_event
时间将屏幕截图复制到剪贴板。
测试
Private Declare PtrSafe 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
Private Declare PtrSafe Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) As Long
Sub Test()
Const Inp_Str As String = "Hello World"
Dim objWord As Object
Dim objDoc As Object
Dim para As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
Set para = objDoc.Paragraphs.Add
para.Range.Text = Inp_Str & vbCrLf & vbCrLf & vbCrLf
para.Range.ParagraphFormat.SpaceAfter = 10
objDoc.Paragraphs.Add
objDoc.Paragraphs.Add.Range.Text = "Line 2 hello"
keybd_event VK_SNAPSHOT, 0, 0, 0
Sleep 500
'Paste into Word This paste is not working
objWord.Selection.Paste
'quit the word application:
objWord.Quit
End Sub
我有一个 VBA 代码可以打开 Attachmate Reflection(IBM Screen)。我想截取 window(如打印屏幕)的完整屏幕截图并将屏幕截图粘贴到 word 文档中。 但是,我无法截取打印屏幕并将其粘贴到 word 中。
为 objWord.Paste 行
获取“对象 属性 或方法不受支持” 'Reflection screen part
Set view = frame.CreateView(terminal)
Set screen = terminal.screen
...
' word document
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
Set para = objDoc.Paragraphs.Add
para.Range.Text = Inp_Str & vbCrLf & vbCrLf & vbCrLf
para.Range.ParagraphFormat.SpaceAfter = 10
objDoc.Paragraphs.Add
objDoc.Paragraphs.Add.Range.Text = "Line 2 hello"
**Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
'Paste into Word This paste is not working
objWord.Paste**
'quit the word application:
objWord.Quit
objWord.Paste
应更改为 objWord.Selection.Paste
。我还需要 Sleep
给 keybd_event
时间将屏幕截图复制到剪贴板。
测试
Private Declare PtrSafe 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
Private Declare PtrSafe Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) As Long
Sub Test()
Const Inp_Str As String = "Hello World"
Dim objWord As Object
Dim objDoc As Object
Dim para As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
Set para = objDoc.Paragraphs.Add
para.Range.Text = Inp_Str & vbCrLf & vbCrLf & vbCrLf
para.Range.ParagraphFormat.SpaceAfter = 10
objDoc.Paragraphs.Add
objDoc.Paragraphs.Add.Range.Text = "Line 2 hello"
keybd_event VK_SNAPSHOT, 0, 0, 0
Sleep 500
'Paste into Word This paste is not working
objWord.Selection.Paste
'quit the word application:
objWord.Quit
End Sub