CommonDialog Reference Issue (1 Viewer)

kenrav

New member
Local time
Today, 09:21
Joined
Jun 20, 2020
Messages
29
I'm trying to create a function that lets users to scan a document and save it to a folder.

I start with "Dim scanDiag As New WIA.CommonDialog"

However, it throws a ""User-defined type not defined" error.

I am referencing the Microsoft Office 16.0 Object Library.

Thanks for your help. If you know of some code that works, that would be fine as well.

Ken
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:21
Joined
Oct 29, 2018
Messages
21,478
Hi. Welcome to AWF!

What is CommonDialog used for? If it's to browse for a file path, then you could try using the FileDialog object instead.

 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:21
Joined
Feb 28, 2001
Messages
27,196
Common Dialog is an old feature.


Look at the FileSystemObject because there are ways to get it to give you a file-picker dialog object.
 

Isaac

Lifelong Learner
Local time
Today, 09:21
Joined
Mar 14, 2017
Messages
8,779
Here is code that I use, this function returns the full file path of the file the user selected.

It requires no references - which is highly preferable, since your users can be on different Office versions and late binding is key to avoiding those problems.

Code:
Function GetUserSelectedAttachment() As String
Dim strFilePath As String
Dim objFD As Object ' Application.FileDialog

' get the file
Set objFD = Application.FileDialog(3) ' msoFileDialogFolderPicker)
With objFD
    'setup File Dialog
    .AllowMultiSelect = False
    .ButtonName = "Select"
    .InitialView = 1 ' msoFileDialogViewList JAH 20110422
    .Title = "Select the attachment"

    'display file dialog box
    If .Show Then
        strFilePath = .SelectedItems(1)
    End If
End With

If (Right(strFilePath, 4) <> "xlsb") And (Right(strFilePath, 4) <> "xlsm") Then 'optional test I use for certain scenario
    GetUserSelectedAttachment = "Invalid"
    Exit Function
End If

GetUserSelectedAttachment = strFilePath

End Function

Credit to JAH , although I can't remember at the moment who that is.
 
Last edited:

bastanu

AWF VIP
Local time
Today, 09:21
Joined
Apr 13, 2010
Messages
1,402
Ken,
You need to reference the WIA library, that is the scanner dialog, not the old deprecated common file dialog:

Cheers,
Vlad
 

Users who are viewing this thread

Top Bottom