Image is one of the UserForm control. You can select and drag Image on the UserForm. You can select and drag Image on the UserForm. Image control embeds a picture such as a jpg, jpeg, gif, png, bitmap, etc. It can be used on the UserForm. You can see how it works and more details about Image Control.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA Image_Control on the UserForm

Please find more details about VBA ActiveX Image_Control on the UserForm.

  1. Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
  2. Go To Insert Menu, Click UserForm. Please find the screenshot for the same.
  3. Drag the Image_control on the Userform from the Toolbox. Please find the screenshot for the same.
  4. Click on the image_control properties.
  5. On the left side find ‘Picture’ from the available properties of the control.
  6. On the right side click on that, and select image from the source.
  7. On the left side find ‘PictureSizeMode’ from the available properties of the control.
  8. On the right side, select ‘1 – frmPictureSiseModeStretch’ from the available list.
  9. Now, Click ‘F5’ to see the output.
  10. Now, you can see the following output as shown below in the screen shot.

Add dynamic Image_Control on the UserForm using VBA

Please find the following steps and example code, it will show you how to add dynamic Image_control on the userform.

  1. Add Image and CommandButton on the userform from the toolbox.
  2. Right click on the CommandButton, click properties
  3. Change the CommandButton caption to ‘Create_Image ’
  4. Double click on the CommandButton
  5. Now, it shows the following code.
  6. Private Sub CommandButton1_Click()
    End Sub
    
  7. Call the below procedure named ‘Add_Dynamic_Image ’ and find the below procedure to run.
  8. Private Sub CommandButton1_Click()
    Call Add_Dynamic_Image 
    End Sub
    

    Procedure to call in the CommandButton:

    Sub Add_Dynamic_Image()
    'Add Dynamic Image and assign it to object 'Img'
    Set Img = UserForm2.Controls.Add("Forms.Image.1")
    With Img
    'Load Picture to Image Control
    .Picture = LoadPicture("C:\Image Excel ActiveX Control Object.jpg") ‘Change Image Path here
    'Align the Picture Size
    .PictureSizeMode = fmPictureSizeModeStretch
    'Image Position
    .Left = 50
    .Top = 10
    End With
    End Sub
    
  9. Now, click F5 to run the macro, click ‘Create_Image ’ button to see the result.
  10. You can see the created dynamic Image_control which is shown in the following screen shot.
  11. output:

    Delete Image_Control on the UserForm using VBA

    Please find the below code, it will show you how to delete or remove the control on the UserForm. In the below example, its deleting the Image named ‘New Image’ which is on the UserForm named ‘UserForm4’. We can use Remove method to delete the controls which are created during run time. Controls which are created during design time cannot be deleted using this method. Please find the below example and screen shots for better understand.

    Code 1: Adding control During Run Time

    Private Sub CommandButton1_Click()
    'We can use Add method to add the new controls on run time
    Set lblBtn = Me.Controls.Add("Forms.Image.1")
    With lblBtn
    .Top = 20
    .Left = 40
    .Name = "lblNew1"
    End With
    MsgBox "New Image Control Added"
    End Sub
    

    Please find the below screen shot for your reference for the above macro and its output.
    When we click on Add Command Button:

    Code 1: Deleting or Removing Image_control which is created during run time.

    Private Sub CommandButton2_Click()
    'We can use Remove method to delete the controls which are created during run time
    'Note: Controls which are created on design time cannot be deleted using this method
    Me.Controls.Remove ("lblNew1")
    MsgBox "Image Control Deleted"
    End Sub
    

    Please find the below screen shot for your reference for the above macro and its output.
    When we click on Delete Command Button:

LIMITED TIME OFFER

Related pages


excel averageif formulahow to protect cells in excel 2007ms excel macros tutorialexcel application statusbaropen excel file from access vbaglobal variables vbaexcel dashboard creation3d scatter excelmicrosoft excel macros tutorialvba code for msgboxhow to hide and unhide columns in excel 2010excel rgb formulamacro excel definitionexcel 2003 vlookupsas tutorial pptfor loop vbavba copy from another workbookmicrosoft word project management templateexcel vba pivot tablessql aptitude questions with answers pdfvlookup in excel formula with exampleexcel vba delete rowsql technical interview questions and answers for freshersvba dsn connection stringboard meeting minutes template microsoft wordglobal variables in vbafree excel 2013 add insvba loop statementmacro buttonsexcel mysql queryexcel tutorial vbawriting macros exceldim worksheetexcel paste special transposevlookup demovariables vbaunlocking an excel spreadsheetmake checkboxes in excelaccess 2007 vba tutorialinteractive excel calendar templateprotect structure and windows excelsql and sas traininghow to write a vlookup formula in excelunprotect workbook excelexcel vba activecell row numberclear formatting excelcreating pivot table in excel 2010delete empty rows excelword activex controlshyperlink examplesexcel vba delete columnoption buttons in excelbuild macro in excelhide unused cells in excelhow to add chart title in excelhow to unlock excel without passwordclearcontents vbaexplain vlookuphow to apply filters in excelto unprotect excel sheetvba for excel bookddl queryeasy excel vbaestimate sheet templatesprogress bar in excel vbaexcel remove duplicates formulafilter vba excelproject portfolio template excelautomation testing interview questions and answers pdfexcel merge macrovba excel averageif iserror vlookup excel 2010access vba copy fileexcel pie chart examplehow to show developer tab in excelsumif excel 2007vba declare global variablehow to create userform in excel 2010