PDA

View Full Version : Solved: Saving contents of Clipboard



Marcster
11-11-2005, 04:07 AM
Hi people http://vbaexpress.com/forum/images/smilies/039.gif,

Does anyone know of a VBA macro to save the contents of the clipboard
(content will be a print screen grab) to a picture file on the pc?. http://vbaexpress.com/forum/images/smilies/think.gif

I've got a VBA macro which takes a screen shot of the users desktop
and copies it to thier clipboard. I now need that picture to be saved
somewhere on their pc, say in C:\ScreenGrabs with the name being the current date. http://vbaexpress.com/forum/images/smilies/100.gif

Is this possible?. http://vbaexpress.com/forum/images/smilies/102.gif

Thanks,

Marcster.

johnske
11-11-2005, 08:18 AM
Never tried it... Maybe paste it onto the worksheet first then use this add-in http://www.andypope.info/vba/gex_addin.zip to export it as a JPG file and then delete the picture from the worksheet?

HTH

Marcster
11-11-2005, 08:23 AM
Hi johnske, i'll have a go and let you know...

Thanks,

Marcster.

johnske
11-11-2005, 11:14 PM
Hi Marcster,

Had a bit of a think and a play around with this idea: You can export and save a chart as a picture (JPG, GIF, etc), you can also paste a picture onto a chart. So if you combine the two... Here's an example, take it from there.

(You say you already have something to obtain the picture, you'd need to amalgamate that with this - otherwise, you'll need to hit "Print Screen" before running this procedure to avoid an error)Sub SavePic()
'don't forget to hit 'Print Screen' first
Charts.Add
With ActiveChart
.ChartType = xlXYScatter
'change Sheet4 to suit
.SetSourceData Source:=Sheets("Sheet4").Range("A1")
.Location Where:=xlLocationAsObject, Name:="Sheet4"
End With
With Sheets("Sheet4")
'set your scale to suit
.Shapes("Chart 1").ScaleWidth 2.5, msoFalse, msoScaleFromTopLeft
.Shapes("Chart 1").ScaleHeight 3.1, msoFalse, msoScaleFromTopLeft
ActiveChart.Paste
'change the name to suit
.ChartObjects(1).Chart.Export Filename:="Demo.JPG", FilterName:="JPG"
.ChartObjects("Chart 1").Activate
Selection.Cut
End With
End Sub
PS: I've never had to do this with VBA because I use a free screen-capture program that allows you to specify exactly what you want captured and how and where you want it saved, try it out, it's available here > http://www.wisdom-soft.com/products/screenhunter_free.htm

Marcster
11-15-2005, 08:57 AM
Thanks johnske :thumb,

This macro works great, thanks again.

Just wondering::think:

How do you delete the chart from the worksheet via VBA?

Also, how do you change the name of the chart
from "Chart 1" to something else, say "Shot1"?

Thanks again,

Marcster.

johnske
11-16-2005, 06:14 AM
Thanks johnske :thumb,

This macro works great, thanks again.

Just wondering::think:

How do you delete the chart from the worksheet via VBA?

Also, how do you change the name of the chart
from "Chart 1" to something else, say "Shot1"?

Thanks again,

Marcster.This mod will delete it. (No need to rename it, it's only intended to be created temporarily and then deleted immediately after. You'd need to use a chart sheet to rename it easily...)Sub SavePic()
Charts.Add
With ActiveChart
.ChartType = xlXYScatter
.Location Where:=xlLocationAsObject, Name:="Sheet4"
End With
With Sheets("Sheet4")
'set your scale to suit
.Shapes("Chart 1").ScaleWidth 2.5, msoFalse, msoScaleFromTopLeft
.Shapes("Chart 1").ScaleHeight 3.1, msoFalse, msoScaleFromTopLeft
ActiveChart.Paste
'change the Filename to suit
.ChartObjects(1).Chart.Export Filename:="Demo.JPG", FilterName:="JPG"
.ChartObjects(1).Activate
Selection.Cut
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
Selection.Cut
End With

Marcster
11-16-2005, 09:44 AM
Ah cool :thumb. Thanks so much.

I'ld like the same to work in Word.
In Word WordBasic.SendKeys "{prtsc}" takes the screenshot

I'll post how I get on in a Word thread.

Thanks again.

Marcster.