How to paste copied clipboard image in Word

2019-08-20 07:38发布

I am trying to take a screenshot, paste it into a new Word document, then save in local area.

Below functions are working:

  1. Create new Word document and save.
  2. Take screen shot.

Issues:

  1. It is taking the screen shot after creating, saving and closing the Word document.
  2. It pastes that screen shot in Excel after executing this code.
  3. It is not pasting that screen shot in the Word document.
  4. I have tried unsuccesfully to paste the screen shot in the Word document with

    • wshShell.SendKeys "^v"

    • wshShell.Selection.Paste

Expectation:

  1. Take a screnshot before creating the Word document.
  2. Automatically paste in the Word document and save.

.

Set wshShell = CreateObject("WSCript.shell")
Sleep 2000
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
Sleep 35000
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Sleep 5000
wshShell.SendKeys "^{v}"
wshShell.SendKeys "~"
Sleep 5000
objDoc.SaveAs ("D:\Srene\sample.docx")
objWord.Quit

1条回答
不美不萌又怎样
2楼-- · 2019-08-20 08:27

Try wait = true

SendKeys string[, wait]

Wait: Optional. Boolean value specifying the wait mode. If False (default), control is returned to the procedure immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.

http://msdn.microsoft.com/en-us/library/gg278655(v=office.14).aspx

查看更多
登录 后发表回答