首页 > 解决方案 > word宏返回工具语法错误

问题描述

出于某种原因,当我运行这个 VBA 宏代码时:

Sub dor()

    Dim DocStats As String
    Dim MBTitle As String
    Dim J As Integer


    With Selection
    .WholeStory
    .LanguageID = wdEnglishUS
    .HomeKey Unit:=wdStory
    End With


    MBTitle = "Readability Statistics"
    DocStats = ""
    With ActiveDocument.Content
        For J = 1 To 10
            'DocStats = DocStats & .ReadabilityStatistics(J)
            'DocStats = DocStats & ": "
            DocStats = DocStats & .ReadabilityStatistics(J).Value
            DocStats = DocStats & vbCrLf
        Next J
    End With


    '~ Create a FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    '~ Provide file path
    outFile = "C:\Users\Dor\Desktop\UrisJobs\work_prod\docx\all_files\output\" & ActiveDocument.Name & ".txt"


    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim objFile As Object
    Set objFile = fso.CreateTextFile(outFile, True, True)

    '~ Setting up file to write
    '~ Set objFile = objFSO.CreateTextFile(outFile, True)


    strComputer = "."


        'Wscript.Echo objFile.Name  'Commented out

        '~ Write to file
    objFile.WriteLine DocStats


    '~ Close the file
    objFile.Close


End Sub

我收到此错误:

“工具语法统计数组不能在包含多于一种语言格式的文档上运行”

我不知道为什么,但是对于某些文档,我的代码正在运行,而对于某些文档,我收到了这个错误。

标签: vbams-word

解决方案


推荐阅读