How to get a range as a picture on a userform

MHD

New Member
Joined
Mar 16, 2021
Messages
49
Office Version
  1. 2019
Hi

I have a range that I need to show on a user form, but I DO NOT want to use a list box. I want the range on the user form to look exactly like the original range on the sheet.

Anyone know the VBA to do this?



The range: sheets ("Invoice_Labor").range("A1:F35")
user form name: UserForm1
Command Button name: CB_Apply

Thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I have seen the results of this issue, but I have not been able to come up with the final code
 
Upvote 0
Sorry but don't understand what you mean. The thread I linked to has all the code.
 
  • Like
Reactions: MHD
Upvote 0
The code is all in post#3 of the linked thread.
 
Upvote 0
Here is a simpler example.

VBA Code:
Sub Example()
    Dim WS As Worksheet, R As Range, Ch As Chart, ChO As ChartObject
    
    Set WS = ActiveSheet
    Set R = WS.Range("A1:D10") 'sample range to display on form
    
    R.CopyPicture xlScreen, xlPicture 'copy the range as a picture
    
    With R 'make temporary chart
        Set ChO = WS.ChartObjects.Add(Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
        Set Ch = ChO.Chart
        ChO.Activate 'this is important
    End With
    
    'paste range pic to chart and save it to a file.
    Ch.Paste
    Ch.Export Filename:="C:\Temp\RangePicture.jpg", Filtername:="JPG"
    DoEvents
    
    Application.DisplayAlerts = False
    ChO.Delete 'delete temporary chart
    Application.DisplayAlerts = True
    DoEvents
    
    'load image to userform (you will need to create this userform containing an image control for this example to work)
    UserForm1.Image1.AutoSize = True
    UserForm1.Image1.Picture = LoadPicture("C:\Temp\RangePicture.jpg") 'load .jpg from file
    UserForm1.Show
End Sub
 
  • Like
Reactions: MHD
Upvote 0
Solution
The code works great
Thank you very much for the interaction

But I am still having a problem
The size of the image that the code has inserted does not correspond to the size of the image area in the user form.
Can we make the code automatically resize the image entered into the user's form?

Is there a solution for that, please
 
Upvote 0
The code works great
Thank you very much for the interaction

But I am still having a problem
The size of the image that the code has inserted does not correspond to the size of the image area in the user form.
Can we make the code automatically resize the image entered into the user's form?

Is there a solution for that, please
Update: can I make the code to pop-up images in the real size as in the sheet in a new window (like a preview)?
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top