LoadPicture Command throwing error

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
323
Good day,

I have a userform with 31 image controls (on for each day of the month of May) which populate with pictures from a folder that are all contain dates (again in May) in the name. I then extract the date from the filename and find the correct image control to place it in. The code works until I try to upload the picture into the image control - throws the error "Compile Error: Wrong number of arguments or invalid property assignment" - not sure what the problem is.


Code:
Private Sub LoadPicture()

Dim FileSys As FileSystemObject
Dim myFolder
Dim strFilename As String
Dim objFile As File
Dim PicDay As Long

'set path for files
Const myDir As String = "[URL="file://\\netapp6\tempstor\John"]\\netapp6\tempstor\John[/URL] Halfyard\Nickel Pictures\GIMP"

'set up filesys objects
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)

'go through tempstor and cycle through pictures
For Each objFile In myFolder.Files
    PicDay = Mid(objFile.Name, 15, 2)  'this returns the day of the month
    'each image control is labelled "Month1, Month2, Month3, etc)
    Me.Controls("Month" & PicDay).Picture = LoadPicture(myDir & Application.PathSeparator & objFile.Name)
Next objFile

Set FileSys = Nothing
Set myFolder = Nothing

End Sub
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,811
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Does it fail for all files or just a particular one? What format are they, and can you manually load them into the control(s)?
 

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
323
The files are in *.jpeg files and yes, I can go into the properties of say "Month1" and under the Picture property load up any of the files. It appears none of the files are getting loaded.
(note, when I manually enter the picture the picture reads "(Bitmap)")
 
Last edited:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,811
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Have you verified that objFile.Name is returning the correct value?
 

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
323

ADVERTISEMENT

Yes, the entire name (with the correction filename extension) reports out when I go a MsgBox. But I had to comment out the "LoadPicture" line to get this even to run. It's not a runtime error and throws an error on compiling.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,811
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Just re-read your code - change the name of your routine to something other than LoadPicture! ;)
 

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
323
okay, I would NOT have gotten that in a million years! And of course, it works like a charm when I renamed it "LoadImage". Nice lesson on 'key words'. Thanks!
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,118,355
Messages
5,571,701
Members
412,413
Latest member
dvprajapati
Top