我想将以下VBA代码转换为VBS脚本。此代码获取当前屏幕的屏幕截图并将其保存在现有文档中。当我尝试时,我得到以下内容:
<'800a0401' expected end of statement> error window.
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
Private Sub Workbook_Open()
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
SendKeys "%{PRTSC}", True
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Users\johnsmith\Documents\Test.doc"
With objWord
.Visible = True
.WindowState = wdWindowStateMaximize
.Selection.Paste
.ActiveDocument.Save
End With
objWord.Quit
Set objWord = Nothing
End Sub
答案 0 :(得分:1)
我找到了一个很好的混合 [Batch / VB.Net] 来截取屏幕截图,所以我与你分享,可能对你有帮助!
/*
@echo off & cls
title DBatchprintscreen
::Autor Delmar Grande
::fórum DBatchScript [url]www.dbatchscript.forumeiros.com/]http://dbatchscript.forumeiros.com/[/url]
::forum Bbat.forumeiro.com [url]www.Bbat.forumeiro.com[/url]
::Data Qui 11 Jul 2013
echo Chargement...
findstr "'%skip%VB" "%~f0" > "%tmp%\%~n0.vb"
for /F %%i in ('dir /B /S ^"%WinDir%\Microsoft.NET\Framework\vbc.exe^"') do set vbc=%%i
if /i "%vbc%"=="" cls & color 1c & echo Ce script a besoin du framework & pause
cls
:7
%vbc% /nologo /out:"%tmp%\%~n0.exe" "%tmp%\%~n0.vb"
"%tmp%\%~n0.exe"
pause
del "%tmp%\%~n0.vb" >NUL 2>&1
del "%tmp%\%~n0.exe" >NUL 2>&1
exit
*/
Imports System.Windows.Forms 'VB
Module ModulePrintscreen 'VB
Sub Main() 'VB
Dim MaDate As String 'VB
SendKeys.SendWait("{%}({PRTSC})") 'VB
If My.Computer.Clipboard.ContainsImage() Then 'VB
MaDate = Format(Now,"dd-MM-yyyy_hh-mm-ss") 'VB
My.Computer.Clipboard.GetImage.Save(MaDate & ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg) 'VB
End If 'VB
End Sub 'VB
End Module 'VB