Forum Discussion
Michetu
Jan 26, 2021Copper Contributor
EXCEL VBA - RUN TIME ERROR '91': OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET
Excel (Version 16.45[microsoft 365]) macOS Big Sur Hi Geniuses! I'm trying to put together a contact manager document in Excel and I'm running into a problem: I want to had two macros...
HansVogelaar
Jan 26, 2021MVP
There are several problems:
- The folder picker dialog doesn't allow you to specify a filter. I think you meant to use the open dialog or the file picker.
- You omitted the . between * and some of the extensions.
- The extensions must be separated by semicolons instead of commas.
Sub Cont_AttachThum()
Dim PicFile As FileDialog
Set PicFile = Application.FileDialog(msoFileDialogOpen)
With PicFile
.Title = "Select a Contact Picture"
.Filters.Add "All Picture Files", "*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.tiff", 1
If .Show <> -1 Then GoTo NoSelection
Sheet2.Range("N4").Value = .SelectedItems(1) 'Put File name in N4
End With
With Sheet2
If .Range("B3").Value = False Then
.Range("L" & .Range("B2").Value).Value = .Range("N4").Value
End With
End With
Cont_DisplayThumb
NoSelection:
End Sub