Hello all,
I am trying to load an image file and I get an Error 2220. The code is as follows. I know it is the line "Me.LogoImage.Picture = Me.OrgLogoPath" that is causing the error but I don't understand what is going wrong. when I debug the line OrgLogoPath = the path to the file but Me.LogoImage.Picture = "None".
Private Sub cmdAddLogo_Click()
On Error GoTo SubError
'Add "Microsoft Office 14.0 Object Library" in references
Dim fDialog As Office.FileDialog
Dim varFile As Variant
OrgLogoPath = ""
' Set up the File Dialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.Title = "Choose the Image you would like to Use"
.AllowMultiSelect = False
' .InitialFileName = "C:\Users\ray\Desktop\Export to Excel" 'Folder picker needs trailing slash
.Filters.Clear
' .Filters.Add "Excel files", "*.xls*"
' .Filters.Add "Excel files", "*.xls"
' .Filters.Add "Excel files", "*.xlsx"
' .Filters.Add "Excel macro-enabled", "*.xlsm"
If .Show = True Then
If .SelectedItems.Count = 0 Then
'User clicked open but didn't select a file
GoTo SubExit
End If
'An option for MultiSelect = False
'varFile = .SelectedItems(1)
'txtSelectedName = varFile
'Needed when MultiSelect = True
For Each varFile In .SelectedItems
OrgLogoPath = OrgLogoPath & varFile & vbCrLf
Me.LogoImage.Picture = Me.OrgLogoPath
Next
Else
'user cancelled dialog without choosing!
'Do you need to react?
End If
End With
SubExit:
On Error Resume Next
Set fDialog = Nothing
Exit Sub
SubError:
MsgBox "Error Number: " & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
"An error occurred"
GoTo SubExit
End Sub