VBA Lesson 33: Excel Image Controls
There is a control in the toolbox called "Image" . Within this control you can show all types of pictures. You set an image control on a userform and you submit a picture in the property "Picture" . The picture becomes part of the control and userform.
Fitting the Picture
The first thing that you want to do is to fit the picture in the image control to make the size of the control adapt to the size of the picture.
When you are in the Visual Basic Editor and you single click on an image control a frame appears around it with 8 stretchers (picture below). If you double click on the middle stretcher (when a two tips arrow shows) of the right side or on the middle one at the bottom or on the bottom right corner stretcher the image control will adapt to the size of the image. Double clicking anywhere else will take you to the VBA code and will not adapt the control size to the picture size.
Another property of the image control is the PictureSizeMode.
If the property is set to the default value 0-frmPictureSizeModeClip the control size can be changed without the picture size being modified. So you can see only part of the picture or there can be a background behind it in a clolor color you can change at will.
If the property is set to the 1-frmPictureSizeModeStretch the picture is resized as the control is. The image fills the control.
If the property is set to the 3-frmPictureSizeModeZoom the picture is resized as the control is but the picture and background are present.
We hope you have enjoyed this introduction to lesson 33
All the Lessons
Lesson 1: Visual Basic Editor (VBE) in Excel, Lesson 2: The Project Window in the Visual Basic Editor of Excel, Lesson 3: The Properties Window in the Visual Basic Editor of Excel, Lesson 4: The Code Window in the Visual Basic Editor of Excel, Lesson 5: Developing Macros in the VBE, Lesson 6: Testing Macros in the VBE, Lesson 7: Excel Macro Recorder, Lesson 8: Macros Help and Assistance, Lesson 9: VBA Events, Lesson 10: VBA Security and Protection, Lesson 11: VBA Coding Tips, Lesson 12: Dealing with Errors, Lesson 13: Working with the Application, Lesson 14: Working with the Workbooks, Lesson 15: Working with the Worksheets, Lesson 16: Moving Around the Worksheet, Lesson 17: Working with Message and Input Boxes, Lesson 18: Excel VBA Vocabulary to Filter and Sort Data. Lesson 19: Working with Variables, Lesson 20: Working with Statements, Lesson 21: Working with Functions, Lesson 22: Working with external data and SQL, Lesson 23: Working with Windows and other Microsoft Programs FROM Excel, Lesson 24: Forms (Userforms) in VBA for Excel, Lesson 25: Userforms Properties and VBA Code, Lesson 26: Properties and VBA code for Command Buttons, Lesson 27: Properties and VBA code for Labels, Lesson 28: Properties and VBA code for Text Boxes, Lesson 29: Properties and VBA code for Combo Boxes, Lesson 30: Properties and VBA code for List Boxes, Lesson 31: Properties and VBA code for Check Boxes, Option Buttons and Frames, Lesson 32: Properties and VBA code for Spin Buttons, Lesson 33: Excel Image Controls
This website and the downloadable Tutorial on Excel Macros are divided in three sections:
Section 1: Excel Macros Programming: Lessons 1 to 10
Section 2: Excel VBA Vocabulary: Lessons 11 to 23
Section 3: Forms and Controls in VBA for Excel: Lessons 24 to 33