1

Does anyone here have any idea how to row Excel's built-in tool (see screenshot below) and automatically select specified window to capture using VBA Script?

enter image description here

Teamothy
  • 2,000
  • 3
  • 16
  • 26

1 Answers1

0

What the code below does is essentially press the shortcut keys: Alt+N+SC+C, where Alt=%, N=Insert Ribbon, SC=Screenshot Button, C= Capture Screen Button, you may have to modify depending on language/office version/shortcut setup. I got it working by running the code from a form control button on the worksheet, running from VBA-editor did not work in this case.

Sub Screenshot()

SendKeys ("%NSCC"), True

End Sub

Note: You should only use the SendKeys Method if no other option is available, because it can cause problems, if the wrong window is active when the code runs.

_

Edit: As you have requested to pick one of the windows in the screenshot gallery, i recommend you find the the SendKeys equivalent of TAB and ENTER. Not the best solution i admit, but better than nothing.

_

Edit2: See this brilliant answer:

Daghan
  • 719
  • 5
  • 17
  • Thanks for the suggestion and reference. Ill try this one – Shan Villahermosa Dec 06 '19 at 14:40
  • It works, I just modify it to %NSC coz I just want to run the screenshot not the screen clipping. One downside though, as you pointed out, the excel file should be a focus window (active window) in the screen in order the for the keyboard shortcut to run as intended. Will try the linked solution – Shan Villahermosa Dec 06 '19 at 14:49