微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MS Word 宏中的“无法获取范围类的 SpecialCell 属性”错误

如何解决MS Word 宏中的“无法获取范围类的 SpecialCell 属性”错误

我有以下宏可以用单独的 Excel 文件中列出的单词替换 Word 文档中的单词。

Function ListfindAndReplace1()
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Dim i As Integer,j As Integer
Dim lastRow As Integer
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open("E:\DropBox\Dictionaries\zJTA.xlsx") 
Set xlWS = xlWB.Worksheets("Sheet1")
lastRow = xlWS.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To ThisDocument.Words.Count - 1 Step 1
For j = 1 To lastRow Step 1
ThisDocument.Words(i) = Replace(ThisDocument.Words(i),xlWS.Cells(j,1).Value,2).Value)
Next j
Next i
Set xlWS = nothing
xlWB.Close True
Set xlWB = nothing
xlApp.Quit
Set xlApp = nothing
End Function

当我运行宏时,以下几行出现错误消息“运行时错误 1004:无法获取范围类的 SpecialCell 属性

lastRow = xlWS.UsedRange.SpecialCells(xlCellTypeLastCell).Row

我尝试了很多东西,但没有用。请帮忙。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。