Wrox Programmer Forums
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2007, 02:07 PM
Registered User
 
Join Date: Sep 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA Error #5132

Hello. I'm trying to get the following VBA/Word code to run (using Word 2000); it's supposed to go into C:\Project\ProjDocs and apply the DelimiterReplace macro to each Word doc in turn. It works great for the first doc, but then chokes on the line:

Set doc = Documents.Open(.FoundFiles(i))

VBA gives an "Run-time error # 5132 Word cannot start converter WPFT632.CNV"

and stops. It never loads any further doc files, and I notice Word has opened a ~$testdoc.doc file (testdoc.doc is the name of the first file in the subdirectory) that looks like gibberish (and is in Normal View, whereas I normally have Word in Page Layout).

Any suggestions will be most appreciated.

Thanks!

Dim i As Integer
Dim doc As Document

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\Project\ProjDocs"
    .SearchSubFolders = False
    .FileType = msoFileTypeWordDocuments
    If Not .Execute() = 0 Then
        For i = 1 To .FoundFiles.Count
            Set doc = Documents.Open(.FoundFiles(i))
            Call DelimiterReplace
            doc.Save
            doc.Close
            Set doc = Nothing
        Next i
    Else
        MsgBox "No files matched " & .FileName
    End If
End With

End Sub

But aft

Larry Landis
Technical Writer
 
Old September 25th, 2007, 04:48 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Apparently the file is a WordPerfect file, and Word doesn't have a converter for WordPerfect files available to it.

Perhaps you can overcome this by adding an error handler. In the error handler, if the Err.Descritpion contains "WPFT", then abandon the current file, and move on to the next.

Which line raises the error? (I would guess it is "Set doc = Documents.Open(...)"

Try:
Code:
Sub . . .()

    On Error GoTo Er

    Dim i        As Integer
    Dim doc      As Document
    Dim AnyError As Boolean

    With Application.FileSearch
        .NewSearch
        .LookIn = "C:\Project\ProjDocs"
        .SearchSubFolders = False
        .FileType = msoFileTypeWordDocuments

        If Not .Execute() = 0 Then

            For i = 1 To .FoundFiles.Count
                Set doc = Documents.Open(.FoundFiles(i))

                If Not AnyError Then
                    Call DelimiterReplace
                    doc.Save
                    doc.Close
                Else
                    AnyError = False ' Reset for next iteration.
                End If

                Set doc = Nothing
            Next i

        Else

            MsgBox "No files matched " & .FileName

        End If

    End With

Rs: Exit Sub

Er: If InStr(Err.Description, "WPFT") <> 0 Then
        AnyError = True
        Resume Next
    End If

    MsgBox Err.Number & ", """ & Err.Description & """"
    Resume Rs

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
vba ado error weazy Excel VBA 2 June 13th, 2006 09:57 PM
Error in VBA script of Access Surfingeurope Access VBA 3 January 30th, 2006 05:58 PM
Combo Box / VBA Error socoolbrewster Access 2 March 19th, 2005 01:03 PM
MS Access and VBA Error Diahann Access VBA 10 January 7th, 2005 05:46 PM
Error when VBA tries to read from SQLDB atlcdp VB Databases Basics 1 December 28th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.