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?
-
Try using the macro recorder, then look at the code and modify as needed to meet your needs. – Darrell H Dec 06 '19 at 11:50
-
^That does not work. One of many things the recorder ignores/reports incorrectly. I have a workaround though – Daghan Dec 06 '19 at 12:16
-
@DarrellH, macro recorder does not capture the screenshot tool – Shan Villahermosa Dec 06 '19 at 14:38
1 Answers
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:

- 719
- 5
- 17
-
-
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