Share via

Adding an image to a label

Anonymous
2011-04-13T17:09:57+00:00

I have the following code that generates three random strings. Example (btn8, btn32, btn16).

Low = 1 

High = 36 

R1 = Int((High - Low

    1. * Rnd()
  • Low) 

R2 = Int((High - Low

    1. * Rnd()
  • Low) 

R3 = Int((High - Low

    1. * Rnd()
  • Low) 

Sheets("ITEMS DATA").Range("K21").Value = "btn" & R1 

Sheets("ITEMS DATA").Range("K22").Value = "btn" & R2 

Sheets("ITEMS DATA").Range("K23").Value = "btn" & R3 

I have a userForm I created in vb that consists of 36 buttons that have images on each button named btn1 through btn36. So after I generate three random "btn's" mentioned above, I would like for the button image to be inserted into three labels named new1, new2, and new3.

How would this code be written?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-04-14T10:47:48+00:00

    You can add images to labels same way as to commandbuttons.

      CommandButton1.Picture = LoadPicture("C:\test.jpg")

      Label1.Picture = CommandButton1.Picture

    Andreas.

    Was this answer helpful?

    0 comments No comments