VBA code for load pictures in a number of multipages, and multiple pages

Mongy

Board Regular
Joined
Dec 9, 2002
Messages
64
Office Version
  1. 365
Platform
  1. Windows
Greetings, hope you've enjoyed your Christmas, and looking forward to the new year!

I'm creating a VBA form for work which launches files and runs macros.
Using a main multipage which breaks up pages such as Files, Macros, Info.
Within the Files and the Macros pages, I've inserted another multipage, breaking the Files into different subject matter (Category A, Category B etc).

At the moment, within the userform initialize, I've added
MultiPageMain.Pages(0).Picture = LoadPicture going up to page 4 pages
MultiPageFiles.Pages(0).Picture = LoadPicture going up to page 10 pages
MultiPageMacros.Pages(0).Picture = LoadPicture going up to page 10 pages

Rather than having multiple lines (20+ lines of code) to load the same picture into each page, is there code to either have ALL multipages (currently 1 main, 2 within) load the same image (1 line of code), or at least for one multipage to load the same image for the 10 pages (3 lines of code).

The number of pages requiring loading might be a little out, but hopefully it makes sense.

Cheers
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Assuming that the code will be run from within the userform code module, the following code will loop through each of the specified multipage controls, and assign the specified image for each page within each multipage control. Change the path and filename accordingly.

VBA Code:
    Dim multiPageNames As Variant
    multiPageNames = Array("MultiPageMain", "MultiPageFiles", "MultiPageMacros")
    
    Dim multiPageName As Variant
    Dim page As Variant
    For Each multiPageName In multiPageNames
        For Each page In Me.Controls(multiPageName).Pages
            page.Picture = LoadPicture("C:\Path\filename.jpg") 'change the path and filename accordingly
        Next page
    Next multiPageName

Hope this helps!
 
Upvote 0
Solution
Assuming that the code will be run from within the userform code module, the following code will loop through each of the specified multipage controls, and assign the specified image for each page within each multipage control. Change the path and filename accordingly.

VBA Code:
    Dim multiPageNames As Variant
    multiPageNames = Array("MultiPageMain", "MultiPageFiles", "MultiPageMacros")
   
    Dim multiPageName As Variant
    Dim page As Variant
    For Each multiPageName In multiPageNames
        For Each page In Me.Controls(multiPageName).Pages
            page.Picture = LoadPicture("C:\Path\filename.jpg") 'change the path and filename accordingly
        Next page
    Next multiPageName

Hope this helps!
Tested, working. I've never been an expert on loops, will have to read up.
Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top