VBA to Take Screenshot of Range

Anonymous
2024-01-16T20:54:22+00:00

Do you mind helping me with a code that will take a screenshot of a range, say, range A1:C10? All the examples I found online were other people doing a lot more than just a simple screenshot (e.g., pasting it into a different range, creating other worksheets to paste there, opening Word and pasting it there, etc.)—way more than I need. I'm no VBA expert and am having difficulty weeding out the code parts I don't need from those examples. I just need it to do the screenshot; I would then (manually) paste it into a specific section of a Word template I use. I can assign the VBA macro to a button in Excel.

Thank you in advance for any help.

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. OssieMac 47,981 Reputation points Volunteer Moderator
    2024-01-17T01:44:13+00:00

    Basically, the manual method is as follows:-

    1. Select the required Excel range.
    2. Right click over selection and select Copy.
    3. Change to Word doc.
    4. Right click where the picture is required.
    5. Select the picture icon from the options displayed (See screen shot with the icon circled in red)

    Image

    If using VBA to copy, then the following code example and then start at step 3 of above.

    Sub Macro1()

    ActiveSheet.Range("A1:C10").Copy 
    

    End Sub

    0 comments No comments
  2. Anonymous
    2024-01-18T01:55:23+00:00

    Thank you for this. That can certainly work with, say, Word and Outlook. Sometimes I paste it in Teams, though. Is there a code for it to take a screenshot or copy the range so that it's copied to the clipboard like a screenshot?

    1 person found this answer helpful.
    0 comments No comments
  3. OssieMac 47,981 Reputation points Volunteer Moderator
    2024-01-18T02:17:52+00:00

    AFAIK it is copied to the clipboard otherwise you would not be able to right click and paste. However, I have not tried it in Teams. Your original question referred to "I would then (manually) paste it into a specific section of a Word template" and the method I provided should do that.

    0 comments No comments
  4. Anonymous
    2024-01-26T16:09:11+00:00

    I've tried this a few times but it's really not a solution that will work, I'm afraid. Pasting the 'picture' to, say, Word or Outlook seems to only paste a table that isn't editable. With normal screenshots, I add a glow formatting to make it stand out from the background and indicate it's a screenshot. But doing that with the suggested method highlights everything in the 'picture' rather than just the edges like normal. I still need to find a way to take an actual screenshot via VBA macro.

    0 comments No comments
  5. Anonymous
    2024-01-27T07:06:30+00:00

    Hi,

    Select a range and export in a folder on desktop

    folder's name: RngAsPic

    if you select the range A1:D5

    file's name is: rng-A1D5

    Add the below vba

    in a regular module .....

    '=================

    Sub RangeAsPicture_Desktop()

    ' ## 27-01-2024 ##

    Dim ws As Worksheet

    Dim rng As Range

    Dim sMain As String, sFd As String, sPath As String, rpl As String

    sMain = CreateObject("WScript.Shell").SpecialFolders("Desktop") & ""

    sFd = "RngAsPic" & ""

    sPath = sMain & sFd

    If Dir(sMain & sFd, vbDirectory) = Empty Then MkDir sPath

    Set rng = Selection

    If MsgBox("select a range ?", vbOKCancel) = vbCancel Then Exit Sub

    Application.ScreenUpdating = False

    Set ws = Worksheets.Add

    Charts.Add

    ActiveChart.Location Where:=xlLocationAsObject, Name:=ws.Name

    With ActiveChart

    With .Parent

    .Height = rng.Height

    .Width = rng.Width

    End With

    rng.CopyPicture xlScreen, xlPicture

    .Paste

    rpl = Replace(rng.Address, "$", "")

    rpl = Replace(rpl, ":", "")

    .Export Filename:=sPath & "rng-" & rpl & ".png", FilterName:="png"

    End With

    Application.DisplayAlerts = False

    ws.Delete

    Application.DisplayAlerts = True

    Application.ScreenUpdating = True

    End Sub

    1 person found this answer helpful.
    0 comments No comments