locked
Compile Error: User-Defined type not defined RRS feed

  • Question

  • Good Afternoon (at least here it is afternoon),

    I have this code block I've been using for years without issue. Today I copied it to another application to incorporate its use there. I am getting a compile error on this line     fDialog As FileDialog

    The block in its entirety is;

    Private Sub doc2docx_Click()
        Dim strFilename As String
        Dim strDocName As String
        Dim strPath As String
        Dim oApp As Object
        Dim oDoc As Object
        Dim fDialog As FileDialog
        Dim intPos As Integer
        Dim strPassword As String
        Dim strWritePassword As String
        Set fDialog = Application.FileDialog(4) ' msoFileDialogFolderPicker
        With fDialog
            .Title = "Select folder and click OK"
            .AllowMultiSelect = False
            .InitialView = msoFileDialogViewList
            If .Show <> -1 Then
                MsgBox "Conversion Cancelled By User", , "List Folder Contents"
                Exit Sub
            End If
            strPath = fDialog.SelectedItems.Item(1)
            If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
        End With
        Set oApp = CreateObject(Class:="Word.Application")
        If oApp.Documents.Count > 0 Then
            oApp.Documents.Close SaveChanges:=-2 ' wdPromptToSaveChanges
        End If
        If Left(strPath, 1) = Chr(34) Then
            strPath = Mid(strPath, 2, Len(strPath) - 2)
        End If
        strFilename = Dir(strPath & "*.doc")
        strPassword = InputBox("Enter password to open the document")
        strWritePassword = InputBox("Enter password to edit the document")
        Do While strFilename <> ""
            Set oDoc = oApp.Documents.Open(FileName:=strPath & strFilename, _
                                      PasswordDocument:=strPassword, _
                                      WritePasswordDocument:=strWritePassword, _
                                      AddToRecentFiles:=False)
            strDocName = oDoc.FullName
            intPos = InStrRev(strDocName, ".")
            strDocName = Left(strDocName, intPos - 1)
            strDocName = strDocName & ".docx"
            oDoc.SaveAs2 FileName:=strDocName, _
                         FileFormat:=12, _
                         CompatibilityMode:=14
            oDoc.Close SaveChanges:=0 ' wdDoNotSaveChanges
            strFilename = Dir
        Loop
        oApp.Quit
    End Sub
    

    My references are in this order;

    Visual Basic For Application

    Microsoft Access 16.0 Object Library

    OLE Animation

    Microsoft Office 16.0 Access Database Engine Object Library

    Microsoft ActiveX Data Objects 6.0 Library

    Microsoft Ward 16.0 Object Library

    Thank you for your assistance with his issue.


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Wednesday, March 27, 2019 9:17 PM

Answers

  • Hi Chris,

    Try adding a reference to the Microsoft Office 16.0 Object Library.

    Hope it helps...

    • Marked as answer by KCDW Wednesday, March 27, 2019 9:44 PM
    Wednesday, March 27, 2019 9:28 PM

All replies

  • Hi Chris,

    Try adding a reference to the Microsoft Office 16.0 Object Library.

    Hope it helps...

    • Marked as answer by KCDW Wednesday, March 27, 2019 9:44 PM
    Wednesday, March 27, 2019 9:28 PM
  • Of course that's the answer...

    I thought I had that one. Even thought I included it in my post. Guess I couldn't see the forest for the trees today.

    Thank you .theDBguy


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Wednesday, March 27, 2019 9:45 PM
  • Hi Chris. You're welcome. Glad to hear it worked for you. Cheers!
    Wednesday, March 27, 2019 9:57 PM