1

I'm using the Excel Add-in ExceltoWord to auto-populate a Word Document from an Excel worksheet. I've followed the instructions from the original developer here.

I'm using the "I created generic bookmark indicators, in Word" and "I put bookmark indicators directly in cells - Left" options with "Delete the Word doc" at the end. When I save settings I get an MS Visual Basic error

Run-time error '429:' ActiveX component can't create object.

I've tried switching different formats of Excel sheet and Word Doc and Word Template as well as leaving the Word Doc closed and opened when saving the configuration.

Public Function validateFileFolderSelection(ByVal fName As String, fType As String, src As String, bFolderOnly As Boolean) As Boolean

'Dim FSO As FileSystemObject 'early binding
Dim FSO As Object 'late binding


    'Set FSO = New FileSystemObject 'early binding
    Set FSO = CreateObject("Scripting.FileSystemObject") 'late binding

    validateFileFolderSelection = True

    'Test for word or excel filename & that the file exists
    If Trim(fName) = vbNullString Then
        validateFileFolderSelection = False
    ElseIf bFolderOnly Then
        If Not FSO.FolderExists(fName) Then
            validateFileFolderSelection = False
        End If
    ElseIf Not FSO.fileExists(fName) Then
            validateFileFolderSelection = False
    End If

End Function

VBA displays an error on Set FSO = CreateObject("Scripting.FileSystemObject") 'late binding.

Robert Todar
  • 2,085
  • 2
  • 11
  • 31
Seth Kasten
  • 43
  • 1
  • 8
  • Do you use a Mac? – Storax May 31 '19 at 14:25
  • No, using Windows 7 Enterprise. – Seth Kasten May 31 '19 at 14:35
  • Ok, then `Scripting` should be installed, right? – Storax May 31 '19 at 15:13
  • Maybe [this](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/activex-component-can-t-create-object-or-return-reference-to-this-object-error-4) is of any help – Storax May 31 '19 at 15:26
  • Scripting is installed. I double checked to make sure ActiveX is enabled and allowed and it is. I checked out the link, and I don't think any of the troubleshooting provided would help. I don't see why the class would be an issue since I'm using standard Excel and Word files, and the Desktop is nearly new, so I don't think it's a DLL issue. – Seth Kasten May 31 '19 at 16:13
  • Your posted code is working for me. I am afraid I do not have any other ideas based on the given information what could be wrong. – Storax May 31 '19 at 17:05
  • I am running this on a virtual desktop. Could that be related to the problem? – Seth Kasten May 31 '19 at 17:15

1 Answers1

1

If you add a Reference to Microsoft Scripting Runtime (VBE > Tools > References...) then enable the "Early Binding" code that you currently have commented out, and your code will work.

To set the reference in the Visual Basic Editor (VBE) go to the Tools menu and select the References... function.

enter image description here

Then from the References dialog that opens, scroll until you locate Microsoft Scripting Runtime, and mark it and then click OK.

enter image description here

In your current code remove the comment marks on the two lines marked as "Early Binding" and apply comment marks on the two lines marked as "Late Binding".

The following is an edit to the original answer because, based on comments, you are continuing to have problems with using FSO (File System Object) code on your system.

Instead of using FSO the following VBA routine will determine if either a specified Directory or File exists. The routine is called "DoesItExist" and I have included an example routine that demonstrates how to call the "DoesItExist" routine.

Sub MyTestRoutine()
    'this first example tests if a specific file exists
    'including a "False" setting for the dirOnly variable is optional
    If DoesItExist("C:\Users\<userID>\Documents\Test\Mydoc.docx") Then
        Debug.Print "File Exists"
    Else
        Debug.Print "File Does Not Exist"
    End If
    'the next example tests if a directory exists,
    'the "True" setting for the dirOnly variable is required for directories
    If DoesItExist("C:\Users\<userID>\Documents\Test", True) Then
        Debug.Print "Directory Exists"
    Else
        Debug.Print "Directory Does Not Exist"
    End If
End Sub

Public Function DoesItExist(ByRef pathName As String, Optional ByRef dirOnly As Boolean) As Boolean
    'this routine checks if a file or folder exists on the system
    'it runs on either a Windows based version of Office or a Mac version
    'if Mac Office then only for the Office 365, 2016, 2019, or later)
    Select Case dirOnly
        Case True
            If Dir(pathName, vbDirectory) = vbNullString Then
                DoesItExist = False
            Else
                DoesItExist = True
            End If
        Case False
            If Dir(pathName, vbNormal) = vbNullString Then
                DoesItExist = False
            Else
                DoesItExist = True
            End If
    End Select
End Function
Rich Michaels
  • 1,663
  • 2
  • 12
  • 18
  • Though I do not think this will help it is a good idea to check. I guess the same error will occur again and that means something is wrong with MS Scripting Runtime. – Storax May 31 '19 at 15:24
  • In all honesty, I'm very unfamiliar with VBE and a novice at coding, so I'm not entirely sure where to go or what to do after VBE > Tools > References apart from enabling ExcelToWord, which is already done. – Seth Kasten May 31 '19 at 16:23
  • @SethKasten, I've edited my answer to include instructions for adding the Microsoft Scripting Runtime reference. – Rich Michaels May 31 '19 at 17:17
  • Thanks for the help. It didn't seem to fix the problem. Instead I got an error on the Publict Function validateFileFolderSelection line. I also tried running it again with late binding with Microsoft Scripting Runtime enabled and got the Run-time 429 error again. – Seth Kasten May 31 '19 at 17:32
  • @SethKasten, you appear to now have a different error that is not related to the first one you posted. If you are receiving an error on the Public Function statement, that cannot be related to the Scripting Runtime reference. – Rich Michaels Jun 01 '19 at 11:54
  • @SethKasten, I have edited the answer above to include an alternate way to check if a file or folder exists. It does not use the FSO function. – Rich Michaels Jun 01 '19 at 12:59
  • I added your code and deleted the FSO function. I still get the Run-time 429 error. I don't think it's a problem with code at this point but a problem with Excel trying to pull a file from a Network drive. I'm running on a virtual desktop server and sometimes the shared server directories don't behave normally. Thanks for the help! – Seth Kasten Jun 03 '19 at 15:39