I would like to understand the correct syntax for late binding and early binding with FileDialog.
A few Google searches have shown the following snippets of code for other objects, such as an instance of Outlook:
However... I am not sure how to use binding correctly with FileDialog.
Here is what I have tried:
Any advice on the correct syntax here for late/early binding with FileDialog much appreciated.
I'm not sure why it doesn't behave the same way as for Outlook.Application.
A few Google searches have shown the following snippets of code for other objects, such as an instance of Outlook:
VBA Code:
Sub Outlook1()
'Late binding.
'No reference to library needed and no Intellisense.
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
End Sub
Sub Outlook2()
'Early binding.
'Needs reference to "Microsoft Outlook 16.0 Object Library". Intellisense works.
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
End Sub
Sub Outlook3()
'Quite commonly seen and seems to work as early binding.
'Needs reference to "Microsoft Outlook 16.0 Object Library". Intellisense works.
'But... inconsistent syntax (mishmash of 1 and 2 above) and frowned upon.
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
End Sub
However... I am not sure how to use binding correctly with FileDialog.
Here is what I have tried:
VBA Code:
Sub Dialog1()
'Late binding - is this ok?
Dim Dialog As Object
Set Dialog = Application.FileDialog(msoFileDialogFilePicker)
End Sub
Sub Dialog2()
'Early binding attempt - doesn't compile (can't use "FileDialog" with New).
Dim Dialog As FileDialog
Set Dialog = New FileDialog
End Sub
Sub Dialog3()
'This appears to work as early binding: Intellisense works.
'But it looks like the "inconsistent syntax / mishmash" example mentioned in "Outlook3".
Dim Dialog As FileDialog
Set Dialog = Application.FileDialog(msoFileDialogFilePicker)
End Sub
Any advice on the correct syntax here for late/early binding with FileDialog much appreciated.
I'm not sure why it doesn't behave the same way as for Outlook.Application.
Last edited: