excel - MS Word 宏中的“无法获取范围类的 SpecialCell 属性”错误
问题描述
我有以下宏将 Word 文档中的单词替换为单独的 Excel 文件中列出的单词。
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, xlWS.Cells(j, 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
我尝试了很多东西,但没有用。请帮忙。
解决方案
推荐阅读
- java - 如何使用java从文本文件中删除重复的单词
- python - 您将如何解释以下内容:Python 中的 [position*-1]?* 让我失望
- qt-creator - 如何从侧边栏中删除项目?
- node.js - 来自不同 Web 服务的嵌套 axios 请求
- multithreading - 在子进程中运行的线程没有按照设置的警报时间超时
- cucumber-java - PIT-Cucumber 插件未在功能文件中找到场景
- node.js - 如何使用 Electron 和 React 显示从文件中读取的数据?
- reactjs - 当我更新浏览器时,React-router 渲染组件
- c# - 如何在 IdentityServer4 中为声明添加角色?
- git - 当您需要同时处理多个功能时的 Git 策略