Capture Screen Shot
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Capture Screen Shot
Hi All
i want to capture active window and save that image (PNG) in a folder. (Window 11)
is this possible with VBA..
i make this thread in "outlook" as i want to capture mail snap actually.
Adeel
i want to capture active window and save that image (PNG) in a folder. (Window 11)
is this possible with VBA..
i make this thread in "outlook" as i want to capture mail snap actually.
Adeel
-
- Administrator
- Posts: 79952
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
thx for your reply but this did not work...
Adeel
Adeel
-
- Administrator
- Posts: 79952
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
-
- PlutoniumLounger
- Posts: 16694
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Capture Screen Shot
The code below is from my utility library UW.dot
You will need a defined constant
Code: Select all
Public Const VK_SNAPSHOT = &H2C ' for ActiveScreenToClipboard
Code: Select all
Public Function ActiveScreenToClipboard()
' Procedure : ScreenToClipboard
' Description: Simulate the PrtScr key.
' Copyright: Christopher Greaves
' Inputs: None
' Returns: None.
' Assumes: None.
' Side Effects: Clipboard contents change.
' Tested: By a call from the user.
' This code compliments of Q240653 & Kevin Paddock of www.wopr.com (Woody's Lounge)
keybd_event VK_SNAPSHOT, 1, 0, 0
' To test this code, indulge me:
' Run the macro, then open up Paint, Paintbrush, or any other graphics editor
' and within the graphics editor choose Edit Paste.
' You should see a snapshot of ALL OF the screen as it was at the time you ran the macro.
'
' I suppose you could use this macro to trap a snapshot at the time an error was detected
' and generate an error report with the screen contents attached.
End Function
Public Function ActiveWindowToClipboard()
' Procedure : ActiveWindowToClipboard
' Description: Simulate the Alt-PrtScr key combination.
' Copyright: Christopher Greaves
' Inputs: None
' Returns: None.
' Assumes: None.
' Side Effects: Clipboard contents change.
' Tested: By a call from the user.
'This code compliments of Q240653 & Kevin Paddock of www.wopr.com (Woody's Lounge)
keybd_event VK_SNAPSHOT, 0, 0, 0
' To test this code, indulge me:
' Run the macro, then open up Paint, Paintbrush, or any other graphics editor
' and within the graphics editor choose Edit Paste.
' You should see a snapshot of PART OF the screen as it was at the time you ran the macro.
'
' I suppose you could use this macro to trap a snapshot at the time an error was detected
' and generate an error report with the screen contents attached.
End Function
Not a single one of our ancestors died in infancy (Richard Dawkins “River out of Eden”)
-
- SilverLounger
- Posts: 2173
- Joined: 25 Jan 2010, 02:12
Re: Capture Screen Shot
Why don't you just use the snipping tool and not have to write something?
Joe
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
right now doing as you say, more then 100 images need to save of different emails, i am looking one click solution rather take snap ,ctrl+S then save in folder...Why don't you just use the snipping tool and not have to write something?
Adeel
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
@Chris
thx for your help
when i paste your code in outlook module its shows error "keybd_event" function not defined
Adeel
thx for your help
when i paste your code in outlook module its shows error "keybd_event" function not defined
Adeel
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
i found this code
this is working well but in excel when i run from outlook its showing error in different line i tried to change lines but hasn't succeed.
source code link: https://stackoverflow.com/questions/745 ... o-a-folder
Adeel
this is working well but in excel when i run from outlook its showing error in different line i tried to change lines but hasn't succeed.
source code link: https://stackoverflow.com/questions/745 ... o-a-folder
Code: Select all
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
Private Const VK_SNAPSHOT = &H2C
Private Const KEYEVENTF_KEYUP = &H2
Private Const PREFIX As String = "<My folder>\"
Sub PrintScreen()
' grab filename
Dim fileName As String
fileName = ActiveCell.Value
' activate, for example, Chrome ... this will only work if Chrome is already in
' a 'normal' or 'maximized' window (ie not 'minimized')
AppActivate "Chrome", False
' take screenshot
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
' wait for screenshot
Dim t As Single
t = Timer + 0.1
Do While Timer < t
DoEvents
Loop
' paste screenshot to sheet and grab it ... the active sheet must be
' a Worksheet for this to work
ActiveSheet.Paste
Dim shp As Shape
Set shp = Selection.ShapeRange(1)
' save as file ... PNG in this case
If ExportPicture(shp, PREFIX & fileName & ".png", "png") Then
' do success stuff!
Debug.Print "Success"
Else
' do failed stuff!
Debug.Print "Failed"
End If
' optionally, if required, delete the screenshot
shp.Delete
End Sub
' Export Shape, as a picture, to a file
Function ExportPicture(shp As Shape, sFile As String, sFilter As String) As Boolean
On Error GoTo errExit
Dim ch As ChartObject
Set ch = shp.Parent.ChartObjects.Add(0, 0, shp.Width, shp.Height)
ch.Activate
ch.ShapeRange.Fill.Visible = msoFalse ' to allow transparency if PNG
ch.ShapeRange.Line.Visible = msoFalse
ch.Chart.Paste
ch.Chart.Export sFile, sFilter
ExportPicture = True
errExit:
If Not ch Is Nothing Then ch.Delete
End Function
Share
Improve this answer
Follow
answered Nov 27, 2022 at 12:50
JohnM's user avatar
JohnM
1,347
-
- PlutoniumLounger
- Posts: 16694
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Capture Screen Shot
Adeel, I offer my my apologies.
I have assembled the VBA code in an MSWord2003 document (attached).
Please try testing/running the procedures in MSWord before Outlook. My VBA experience in mainly in MSWord. Once we are happy that they work for you in MSWord you can try porting them over to MSOutlook.
I re-ran the tests; i suspect that the procedure ActiveWindowToClipboard is not functioning as it should. I know it worked twenty years ago, but something might be different with Win 11.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.
Not a single one of our ancestors died in infancy (Richard Dawkins “River out of Eden”)
-
- SilverLounger
- Posts: 2173
- Joined: 25 Jan 2010, 02:12
Re: Capture Screen Shot
Is your objective to save a copy of the email easily outside of Outlook? Does it have to be a picture?
Joe
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
Hi @Charis Good Morning
thx for your help
when i open file there is one red at top but this not make any effect i think this Code is 2 times in code ActiveScreenToClipboard this only show capture option and copy to clipboard then nothing is happening.
and when i am running this code "lngClipboard" nothing happening
if i overall hit F5 then code is doing nothing.
many thx
Adeel
thx for your help
when i open file there is one red at top but this not make any effect i think this Code is 2 times in code ActiveScreenToClipboard this only show capture option and copy to clipboard then nothing is happening.
and when i am running this code "lngClipboard" nothing happening
if i overall hit F5 then code is doing nothing.
many thx
Adeel
You do not have the required permissions to view the files attached to this post.
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
-
- Administrator
- Posts: 79952
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Capture Screen Shot
Disk storage is extremely cheap nowadays, so I wouldn't worry about the space taken up by email messages.
Moreover, deleting email messages and keeping only a picture of them is a bad idea - you can easily search for text in email messages, but searching for text in pictures is very tedious.
Moreover, deleting email messages and keeping only a picture of them is a bad idea - you can easily search for text in email messages, but searching for text in pictures is very tedious.
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 16694
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Capture Screen Shot
Adeel, did you try running the TEST procedure for each of these procedures?
"Please try testing/running the procedures in MSWord"
Each TEST procedure comes with a brief explanation of what should result. For some of the TEST procedures you will need to have MSPaint and NotePad open to actually see that the clipboard is being loaded, cleared etc. Those TEST procedures that use Debug.Assert should run to completion with no interruptions. There is limited VBA help for Debug.Assert. Where one TEST procedure depends on another procedure, be wise and test the other procedure FIRST to convince yourself that that procedure is working before using it in another TEST procedure.
If you want to see how the procedures work, you can single-step through them in the normal manner.
Cheers, Chris
Not a single one of our ancestors died in infancy (Richard Dawkins “River out of Eden”)
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
i totally agreed sir, your and JOE point is very much strong and valid.HansV wrote: ↑28 Jul 2023, 07:09Disk storage is extremely cheap nowadays, so I wouldn't worry about the space taken up by email messages.
Moreover, deleting email messages and keeping only a picture of them is a bad idea - you can easily search for text in email messages, but searching for text in pictures is very tedious.
PIC has limitation for cropping and each person can be crop in different angle/Way and it also fixed in size and also cannot be go thorough bottom to top etc. for future investigation in case of query ect.
But i will raise this same with Line but till then i have to do it like this.
Adeel
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
Hi Chris sir
thx i will get back to you
Adeel
thx i will get back to you
Adeel
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: Capture Screen Shot
thx Chris for your idea/Suggestion!
i got solve my issue.
Take a pic from outlook and move that pic in excel and Export in folder...
Adeel
i got solve my issue.
Take a pic from outlook and move that pic in excel and Export in folder...
Adeel