|
大佬们好,小弟刚开始学,在论坛上的一个帖子里复制别的人代码学习,结果出现“用户定义类型未定义”错误,找不到错哪,能帮我看一下吗?万分感谢!
原贴地址:http://club.excelhome.net/thread-801791-2-1.html
原贴附件:
新建文件夹.zip
(4.22 KB, 下载次数: 6)
原贴大佬代码:
下面的程序在word 2010中实现。
注意:
(1)需要在 工具 -》引用 中勾选 office excel 选项;
(2)excel文件不是xls,而是xlsx;(3)录制宏时,选择按钮;
Sub BatchReplace()
'
' BatchReplace 宏
'
'
'(1)需要在 工具 -》引用 中勾选 office excel 选项;
'(2)excel文件不是xls,而是xlsx;
'(3)录制宏时,选择按钮
'声明Excel相关
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim sheet As Excel.Worksheet
'获取指定excel程序
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open("C:\test.xlsx")
Set sheet = xlBook.Worksheets(1)
Dim i
Dim nLR
nLR = ActiveSheet.Cells.SpecialCells(xlLastCell).Row '最后一行
For i = 1 To nLR
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = sheet.Cells(i, 1)
.Replacement.Text = sheet.Cells(i, 2)
'MsgBox (.Text)
'MsgBox (.Replacement.Text)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
'退出指定excel程序
xlBook.Close 0
xlApp.Quit
Set xlApp = Nothing
End Sub
|
|