如何用VBA实现WORD批量替换?
For i = 1 To n 'n是listview1的行数Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = ListView1.ListItems(i).SubItems(0) 'Findstr=listview1的第i行第1列对应单元格的内容.Replacement.Text = ListView1.ListItems(i).SubItems(1) 'Findstr=listview1的第i行第2列对应单元格的内容.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllListView1.selectedItem = iNextMsgBox "处理完毕!", vbInformation + vbOKOnly, "消息"ListView1.selectedItem = 1
怎么把身份证号码从word里批量复制到excel里?
展开全部 切记!!首先要把EXCEL的单元格格式设为文本格式,否则18位身份证号进去就kjn#$# *&WORD中的号码若是每行一个的,你直接复制、粘贴过去,就会在EXCEL的一个列里按行放置了最好是在WORD里按行处理后先复制、粘贴的TXT的纯文本文件里(例如WINDOWS记事本),去掉WORD里的格式,再复制到EXCEL里
word里如何禁止复制与另存为?vba编写或宏,或将word文档变成exe...
你在word文档里面插入以下宏:Private Sub Document_Open()If ActiveDocument.ProtectionType = wdNoProtection ThenActiveDocument.Protect _Type:=wdAllowOnlyFormFields, NoReset:=TrueEnd IfEnd Sub如果要高级一点的方法,可以参考官网:http://office.microsoft.com/zh-cn/word-help/RZ001117927.aspx
我想在word的VBA中批量读取段落中的字段,然后做判断。
展开全部 万能的vba可以完成。
以下是以前为客户的代码供参考。
代码如下:Private Sub CommandButton1_Click() '替换页眉及表格数字Dim wdoc As New Word.Application, 当前路径, 导出文件名, 导出路径文件名, i, jDim Str1, Str2Dim tarr(1 To 100, 1 To 2)当前路径 = ThisWorkbook.Path最后行号 = Sheets("数字替换").Range("B65536").End(xlUp).Row判断 = 0filepathname = 当前路径 & "\" & TfileIf Dir(filepathname) = "" Then'文件不存在FileCopy 当前路径 & "\" & Sfile, 当前路径 & "\" & TfileEnd IfSheets("数字替换").SelectFor i = KShh To 最后行号tarr(i - KShh + 1, 1) = Sheets("数字替换").Cells(i, 1)tarr(i - KShh + 1, 2) = Sheets("数字替换").Cells(i, 2)Next ij = i - KShh '记录需替换数字个数导出路径文件名 = 当前路径 & "\" & TfileDim SS As StringDim mySectionDim myTableDim headText As String '页眉表格内数字Dim myCell '页眉表格内单元Dim myFont '页眉表格内单元格式With wdoc.Documents.Open 导出路径文件名.Visible = TrueFor Each mySection In wdoc.ActiveDocument.SectionsFor k = 1 To mySection.Headers.CountSet MYRANGE = mySection.Headers(k).Range '替换页眉中的内容For Each myTable In MYRANGE.TablesFor Each myCell In myTable.Range.CellsheadText = myCell.Range.TextFor i = 1 To j '查找需替换的数字并替换If InStr(headText, tarr(i, 1)) > 0 Then '查找到有要替换的字符串SS = Mid(headText, 1, InStr(headText, tarr(i, 1)) - 1) & tarr(i, 2)myCell.Range.Text = SSEnd IfNext iNext myCellNext myTableNext kNext mySection'替换表格内数字'Set myTable = NullFor Each myTable In wdoc.ActiveDocument.TablesFor Each myCell In myTable.Range.CellsheadText = myCell.Range.TextFor i = 1 To j '查找需替换的数字并替换If InStr(headText, tarr(i, 1)) > 0 Then '查找到有要替换的字符串myCell.Range.Text = tarr(i, 2)End IfNext iNext myCellNext myTableEnd Withwdoc.Documents.Savewdoc.QuitSet wdoc = NothingSheets("首页").SelectEnd Sub
转载请注明出处51数据库 » word批量复制 vba