Show images from worsheets to UserForm

SoloJavier

New Member
Joined
Jan 3, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi guys
I've got a project but I don't know how to solve this:

I want to show an image that already exists in my worksheet using the Image control from UserForm but all the methods that I have seen use the path of the file to insert the image. I can't use this method since I have to share my document to different people so I don't know how to face this situation.

Does anyone have idea of how I can "load" an image by giving the name that appears in the upper left corner of the sheet or something similar?

Thanks in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
All right, I am going offline now for dinner but will return in a couple of days...
 
Upvote 0
Can you write to the user's hard disk?

cof2.PNG


VBA Code:
' UserForm module
Private Sub UserForm_Click()
Dim img
ExportPic
Set img = Me.Controls.Add("Forms.Image.1")
With img
    .Picture = LoadPicture(fn)
    .PictureSizeMode = fmPictureSizeModeZoom
    .Width = 200
    .Height = 150
    .Left = 50
    .Top = 10
End With
Me.CommandButton1.SetFocus
End Sub

' regular module
Public fn$

Sub ExportPic()
Dim ch As Chart, shp As Shape, Sht As Worksheet
Set Sht = ActiveSheet
Set shp = Sht.Shapes(CStr([e118].Value))    ' shape name from cell
Set ch = Charts.Add
ch.Name = "TempPictureChart"
Set ch = ch.Location(Where:=xlLocationAsObject, Name:=Sht.Name)
ch.ChartArea.Width = shp.Width
ch.ChartArea.Height = shp.Height
ch.Parent.Border.LineStyle = 0
shp.Copy
ch.ChartArea.Select
ch.Paste
fn = "d:\test\pic" & Replace(Time, ":", "_") & ".jpg"
ch.Export Filename:=fn, FilterName:="jpg"   ' write to disk
Sht.Cells(1, 1).Activate
Sht.ChartObjects(Sht.ChartObjects.Count).Delete
End Sub
 
Upvote 0
Hi Worf and SoloJavier. Hopefilly a constructive suggestion, instead of using a variable (fn) and/or permanently storing jpg's, I've found the following code useful....
Code:
.Chart.Export Environ$("temp") & "" & "TempChart.jpg", "JPG"

.Picture = LoadPicture(Environ$("temp") & "" & "TempChart.jpg")

Kill (Environ$("temp") & "" & "TempChart.jpg")
You need to add the other code parts of course, but the idea is that it doesn't matter what directories the user has and there is no residual "evidence" that anything ever happened. HTH. Dave
 
Upvote 0
If you place your picture in an activeX image control embeeded in the worksheet, all you need is this :
VBA Code:
UserForm1.Image1.Picture = Sheet1.Image1.Picture
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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