Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can i have a macro that will create a screen shot of my selected window and save it in a folder

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

Stolen shamelessly (but tested) from here:

Sub test()
    Dim cht As Chart
    With Range("A1:E10")
    .CopyPicture Appearance:=xlScreen, Format:=xlPicture
    Set cht = ActiveSheet.ChartObjects.Add(10, 10, .Width, _
    .Height).Chart
    End With
    cht.Paste
    cht.ChartArea.Border.LineStyle = 0
    On Error Resume Next
    Kill "testChart.jpg"
    On Error GoTo 0
    cht.Export "testChart.jpg", "jpg"
    cht.Parent.Delete
End Sub

I assume you mean selected Range, not window, else a keystroke will do. We need to replace Range("A1:E10") with Selection, and wrap it in an error check, because Selections are a little risky


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...