Image load

ebea

Active Member
Joined
Jul 12, 2008
Messages
296
Office Version
  1. 2021
Platform
  1. Windows
Hi! A problem, loading pictures into an image form. I use the image on a UserForm, together with Textboxes, which are loaded by the following code:

But I can't get the images to load as wanted. I have set image name for all rows, into Column O (in this case).
I get the error message "Path not found". And no matter how I set the path, it comes with an error. If I load image "normally", as this: Image1.Picture = LoadPicture("C:\xxx\xxx\1001.jpg") it will works.
Does anybody have a guess of the problem?
Code:
Private Sub CommandButton1_Click()
   Box = TextBox14.Value
    With Sheets("dj")
        For Rows = 3 To .UsedRange.Rows.Count
            If Int(Range("B" & Rows).Value) = Int(Box) Or Range("B" & Rows).Value = Box Then
                TextBox1.Value = .Range("B" & Rows).Value
                TextBox2.Value = .Range("C" & Rows).Value
                TextBox8.Value = .Range("D" & Rows).Value


                Image1.Picture = LoadPicture("C:\xxx\xxx").Range("O" & Rows).Value

Exit Sub
            End If
        Next Rows
    End With
End Sub
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Do you know how to step through the code to see what the value of LoadPicture("C:\xxx\xxx").Range("O" & Rows).Value is?
Does Range("O" & Rows) actually have a .jpg file name?
 
Upvote 0
Yes. The first part of the failure in code "image1.Picture" says "= nothing" when hovering mouse over.
And the .range part in code, find correctly the Row number. And there is a file name in the cells, but only file name (ex. 1001.jpg). The Path is as in the code in my question (xxx is just for examples).
 
Upvote 0
Before line- "Image1.Picture = LoadPicture("C:\xxx\xxx").Range("O" & Rows).Value"
have
Code:
msgbox ("C:\xxx\xxx").Range("O" & Rows).Value
and see what the msgbox shows

Also could you be missing the backslash? and it doesn't appear to have the correct brackets.

Code:
Image1.Picture = LoadPicture("C:\xxx\xxx" & "\" & .Range("O" & Rows).Value)
 
Last edited:
Upvote 0
The msg box shows "C:\pictures\data"
And the code line you did show, gives an error code7 (out of memory)!

Could the problem be related to, that in the Column "O" is both text and number (filename). When I enter, by example a letter together with the lookup number in Textbox 14, it will not work at all, to lookup the value, and return an error message.
 
Upvote 0
... Does anybody have a guess, of the problem in my question. I simply can't figure out, where the problem is related. I have tried a lot of work arounds, without any luck.
I load some TextBoxes, which pick data from a sheet. But I also have one Image1 picture Control (and that's where the problem is), where I should load a related picture to these Text Boxes. I try do the Picture load, with same workaround, as with the Text boxes, by using:
Image1.Picture = LoadPicture("C:\xxx\xxx").Range("O" & Rows).Value

Where I have the image name in Column "O".

Any help, greatly appreciated ;)
 
Upvote 0
Does the file "C:\pictures\data" sound like the correct filename?

You need the complete folder name, file name & file type.

Your out of memory, you should not be using rows as a variable.
 
Upvote 0
Thanks for you'r reply Dave! The Filepath is a synonym (real is a danish name). But path is correct, as it shows up, when I hover mouse over in the error handler (yellow line). I have changed the code line a bit, to be like this:
.Picture = LoadPicture(Filepath) & Range("O" & Rows)

And when I hover over the error handler, it shows the full Filepath, and the correct Row number, and cell address (with Filename),
So it becomes to: "C:\pictures\data\1001.jpg" which are correct
.
So combined, it should load the picture, but don't. If I try in this way: .Picture = LoadPicture("C:\pictures\data\1001.jpg")
the picture is loaded correctly.


So I simply don't understand where the problem is related.

PS:
The error with memory, I'm sure has nothing to do "with reality", but is only an error handler which tells an error number.
 
Upvote 0
No, it's not possible, Dave. As written in my opening question, I load info into TextBoxes, and they all get correct in. And I (try) do the same with the Picture.
It's all loaded from the number, in a specific TextBox, which search Rows, and then the Columns. So it's not possible to have the full string in one. I have tried (as a test) to have the full filepath in the cell, to see if that could return the Picture. But it was also negative :(
So that's why I'm empty of ideas!
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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