Forum Discussion
Load Image from path into Image ActiveX Control in worksheet
- Dec 13, 2022
In such situations, you should temporarily comment out the line
On Error Resume Next
because with it, you won't be notified of any errors.
You declare img as a String, but a String cannot be False. The line
If img <> False Then
causes a Type Mismatch error.
You should declare img as a Variant. That allows it to be any type, whether Boolean (False) or String (a file path).
In the second place, as far as I know, you cannot change the picture on an existing picture shape. You have to delete the existing picture and insert a new one.
Try this version - make sure that there is a shape (any shape) named img_Photo on Sheet3.
Private Sub img_Browse() Dim img As Variant Dim shp As Shape Dim x As Single Dim y As Single Dim w As Single Dim h As Single Dim xCmpPath As String 'On Error Resume Next img = Application.GetOpenFilename(FileFilter:= _ "Pictures (*.jpg;*.png;*.gif;*.bmp),*.jpg;*.png;*.gif;*.bmp") If img <> False Then Set shp = Sheet3.Shapes("img_Photo") x = shp.Left y = shp.Top w = shp.Width h = shp.Height shp.Delete Set shp = Sheet3.Shapes.AddPicture(img, False, True, x, y, h, w) shp.Name = "img_Photo" xCmpPath = img Sheet1.Range("AE1").FormulaR1C1 = xCmpPath End If End Sub
please I want a guide, I'm working on school report card generator with student pictures in excel VBA. I created a drop-down list that contains students reg. No. I have the students pics path in a column and I want to load those picture from it's path into a shape with the picture changing as I change the values on the drop-down list.HansVogelaar
Which version of Office/Excel do you use?
- MuhammadiyyaJun 28, 2024Brass Contributor
office 365 HansVogelaar
- HansVogelaarJun 28, 2024MVP
Excel in Microsoft 365 has a new function IMAGE that inserts a picture into a cell, but it requires a URL, not a local file path. Can you store the images in the cloud, for example on OneDrive, Google Drive or similar?
See IMAGE function
- MuhammadiyyaJun 28, 2024Brass ContributorDoes it mean that without data connection, the image won't be displayed on the cells?