XL98: Using the LoadPicture Function with an Image Control

ID: Q190191


The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition


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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

Creating the User Form and the Macro Code

To create the user form and the macro code, follow these steps:

  1. Save and close any open workbooks, create a new workbook, and then start the Visual Basic Editor by pressing OPTION+F11.


  2. On the Insert menu, click UserForm.


  3. Add an Image control near the upper-center portion of the user form.


  4. 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 


  5. Add a command button control to the user form.


  6. Double-click the command button to open the code window for it.


  7. 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 


  8. To run the user form, press F5.


  9. Click the command button.


An image is loaded into the image control.


REFERENCES

For more information about the Image control, click the Office Assistant in the Visual Basic Editor, type image control, click Search, and then click to view "Things you can do with an Image control".

For more information about the Image control, from the Visual Basic Editor, click the Office Assistant, type image control, click Search, and then click to view "Things you can do with a picture on an Image control."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

Q176476 OFF: Office Assistant Not Answering Visual Basic Questions

Additional query words: XL98

Keywords : kbprg kbdta kbdtacode xlvbahowto xlvbainfo
Version : MACINTOSH:98
Platform : MACINTOSH
Issue type : kbhowto


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.