Consulting

Results 1 to 7 of 7

Thread: Solved: Saving contents of Clipboard

  1. #1
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location

    Question Solved: Saving contents of Clipboard

    Hi people ,

    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?.

    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.

    Is this possible?.

    Thanks,

    Marcster.

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi johnske, i'll have a go and let you know...

    Thanks,

    Marcster.

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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)[VBA]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[/VBA]
    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/...unter_free.htm
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Thanks johnske ,

    This macro works great, thanks again.

    Just wondering:

    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.

  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Marcster
    Thanks johnske ,

    This macro works great, thanks again.

    Just wondering:

    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...)[vba]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[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  7. #7
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Ah cool . Thanks so much.

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

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

    Thanks again.

    Marcster.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •