Microsoft KB Archive/190191

= XL98: Using the LoadPicture Function with an Image Control =

Article ID: 190191

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q190191





SUMMARY
In Microsoft Excel 98 Macintosh Edition, you can add an Image control to a user form. The following are two ways to specify which picture file is displayed in the Image control:


 * You can specify the picture at design time -or-


 * You can specify the picture at run time.

NOTE: The technique you use depends on whether you want to store the picture file with your project.

The advantage of using the run-time method is that the picture file is not stored with the project, which minimizes the size of the project. However, if you distribute the project to others, you must remember to include the picture file with the project file, and you must provide instructions for placing the picture file in the correct location.

This article provides a sample Visual Basic for Applications macro that uses the LoadPicture function to load a picture file into an Image control during run time.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Creating the User Form and the Macro Code
To create the user form and the macro code, follow these steps:

 Save and close any open workbooks, create a new workbook, and then start the Visual Basic Editor by pressing OPTION+F11. On the Insert menu, click UserForm. Add an Image control near the upper-center portion of the user form.  To activate the Properties window, press F6. Set the values for the properties of the Image control as described by the following list:      Property   Value Name      Image1 AutoSize  True Height    100 Width     100  Add a command button control to the user form. Double-click the command button to open the code window for it.</li>  Type the following code into the code window: Private Sub CommandButton1_Click

' Loads a clipart image into the Image control. ' NOTE: Replace "Macintosh HD" with the name of your hard disk. Image1.Picture = LoadPicture("Macintosh HD:Microsoft Office 98:" & _         "Clipart:Popular:Agree")

End Sub </li> To run the user form, press F5.</li> Click the command button.</li></ol>

An image is loaded into the image control.

<div class="references_section">