This approach will put a picture of the selected range into a UserForm (i.e., select a range, then run the procedure that loads the UserForm). It's simpler than the Windows API approach linked to in the other answer.
What it does is copy the selected range as a bitmap picture, paste it into a temporary chart that contains no data, exports the chart as a GIF image, then loads the GIF into the image control on the UserForm.
You can make the program more elaborate: you can resize the image control to fit the picture of the range, you can resize the UserForm to accommodate the image control, you can use an input box to ask the user what range to put into the image control, etc.
Create a UserForm, and name it F_PicRangeIntoImage.
Add an image control, and name it imgRange.
Make the image control and userform large enough for the selected range.
Put this code into the UserForm, along with all other code needed for its functionality:
Code:
Private Sub UserForm_Initialize()
Dim sExportName As String
Dim sPathName As String
Dim sFileName As String
Dim rSelection As Range
Dim oSelection As Object
sPathName = Environ("tmp") ' temp directory
sFileName = "temp.gif" ' can't handle png
sExportName = sPathName & Application.PathSeparator & sFileName
Set oSelection = Selection
If TypeName(oSelection) = "Range" Then
' no shape selected
' make new shape to hold selected range
Set rSelection = oSelection
bExport = ExportRangeAsPictureFile(rSelection, sExportName)
If Not bExport Then btnClose_Click
Me.imgRange.Picture = LoadPicture(sExportName)
Else
Me.Hide
Exit Sub
End If
End Sub
Put this code into a regular module.
Code:
Sub LoadSelectionIntoImgOnUserForm()
Dim frm As F_PicRangeIntoImage
Set frm = F_PicRangeIntoImage
With frm
.Show
End With
Unload frm
End Sub
Function ExportRangeAsPictureFile(rExport As Range, sExport As String) As Boolean
Dim dh As Double, dw As Double
dh = 1
dw = 1
On Error Resume Next
Kill sExport
On Error GoTo 0
If rExport Is Nothing Then GoTo Exit_Func
rExport.CopyPicture appearance:=xlScreen, Format:=xlBitmap
With ActiveSheet.ChartObjects.Add(Left:=rExport.Left, Top:=rExport.Top, _
Width:=rExport.Width + dw, Height:=rExport.Height + dh)
DoEvents
With .Chart
Do Until .Pictures.Count = 1
DoEvents
.Paste
Loop
.ChartArea.Format.Line.Visible = msoFalse
.Export sExport
ExportRangeAsPictureFile = True ' it worked
End With
.Delete
End With
Exit_Func:
End Function