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



## Mongy (Dec 29, 2022)

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


----------



## Domenic (Dec 29, 2022)

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.


```
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!


----------



## Mongy (Dec 29, 2022)

Domenic said:


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


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


----------



## Domenic (Dec 29, 2022)

You're very welcome, cheers!


----------

