用户登录
用户注册

分享至

word 批量多关键词替换 vba word vba 批量替换

  • 作者: 疯子的枫叶YYYY
  • 来源: 51数据库
  • 2020-04-15

word 批量多关键词替换 vba

word vba问题 如何批量替换文件夹内所有的WORD文档内相同的词组...

Sub 批量修改()'On Error Resume NextDim FileOpenDim X As IntegerDim wb As WorkbookApplication.ScreenUpdating = FalseFileOpen = Application.GetOpenFilename(FileFilter:="Microsoft Excel文件(*.xls),*.xls", MultiSelect:=True, Title:="选择工作薄")X = 1While X Set wb = Workbooks.Open(FileOpen(X))wb.Sheets(1).[a1] = "456"wb.Sheets(1).[D4] = "王月"wb.Close TrueX = X + 1WendEnd Sub这个宏 会把 你选中的文件 批量替换 sheet1 :A1的内容 改为 456 D4 的内容改为 王月, 你可以根据你的实际情况修改代码就可以了, 如果单元格不固定就 用FIND 方法找到再修改

在word 中如何批量替换关键词?

Sub 批量操作WORD() Dim path As String Dim FileName As String Dim worddoc As Document Dim MyDir As String MyDir = "G:\360data\重要数据\桌面\新建文件夹 (2)" '文件夹路径根据需要自己修改,需要处理的文件都放该文件夹内 FileName = Dir(MyDir & "\*.doc*", vbNormal) Do Until FileName = "" If FileName ThisDocument.Name Then Set worddoc = Documents.Open(MyDir & "\" & FileName) worddoc.Activate Call 处理WORD '调用宏,换成你自己宏的名字 worddoc.Close True FileName = Dir() End If LoopSet worddoc = NothingEnd Sub'======================下面的宏换成你自己的宏=================================Sub 处理WORD() ActiveDocument.Paragraphs(1).Range.Select Selection.Font.Size = 72End Sub

word VBA替换文字和删除页面问题!请各路大神前来帮助。

示例代码如下:Sub 宏1()For i = 1 To ThisDocument.Tables.Counts = ThisDocument.Tables(i).Cell(1, 2).Range.TextIf Trim(s) = "" ThenMsgBox ("无数据" & s)ElseMsgBox ("有数据" & s)End IfNextEnd Sub

怎么vba实现word表格批量转为excel

注:vba偶并不太熟(偶一般是用c#和delphi的),VBA只是稍有了解,以下代码大部分是偶google到的内容拼出来的。

如下,使用时先更改test下的docpath和xlspath路径设定,docpath即你的word的目录,此目录包括子目录下的所有doc将被读取,xlspath即输出目录,需要存在 在VBA窗口中,先在视图下显示立即窗口以观察进度,程序最后的输出类似这样 正在读取[1]:->D:\1\Resume.doc 正在生成:->d:\2\Resume 正在读取[2]:->D:\1\简历(简).doc 正在生成:->d:\2\简历(简) 正在读取[3]:->D:\1\计数器说明.doc 正在生成:->d:\2\计数器说明 共耗时0分41秒 Option Explicit Dim docpath As String, xlspath As String'ResultFlag=0 获取路径'ResultFlag=1 获取文件名'ResultFlag=2 获取扩展名 Public Function SplitPath(FullPath As String, ResultFlag As Integer) As String Dim SplitPos As Integer, DotPos As Integer SplitPos = InStrRev(FullPath, "\") DotPos = InStrRev(FullPath, ".") Select Case ResultFlag Case 0 SplitPath = Left(FullPath, SplitPos - 1) Case 1 If DotPos = 0 Then DotPos = Len(FullPath) + 1 SplitPath = Mid(FullPath, SplitPos + 1, DotPos - SplitPos - 1) Case 2 If DotPos = 0 Then DotPos = Len(FullPath) SplitPath = Mid(FullPath, DotPos + 1) Case Else Err.Raise vbObjectError + 1, "SplitPath Function", "Invalid Parameter!" End Select End Function Public Function FileFolderExists(ByVal strFullPath As String) As Boolean On Error GoTo EarlyExit If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True EarlyExit: On Error GoTo 0 End Function Sub Test() '使用双字典,旨在提高速度 Dim MyName, Dic, Did, I, T, F, TT, MyFileName, Doc, Ke Dim count As Integer count = 0 T = Time docpath = "D:\1\" xlspath = "d:\2\" Set Dic = CreateObject("Scripting.Dictionary") '创建一个字典对象 Set Did = CreateObject("Scripting.Dictionary") Dic.Add (docpath), "" I = 0 Do While I Ke = Dic.keys '开始遍历字典 MyName = Dir(Ke(I), vbDirectory) '查找目录 Do While MyName "" If MyName "." And MyName ".." Then If (GetAttr(Ke(I) & MyName) And vbDirectory) = vbDirectory Then '如果是次级目录 Dic.Add (Ke(I) & MyName & "\"), "" '就往字典中添加这个次级目录名作为一个条目 End If End If MyName = Dir '继续遍历寻找 Loop I = I + 1 Loop 'Did.Add ("文件清单"), "" '以查找D盘下所有EXCEL文件为例 For Each Ke In Dic.keys MyFileName = Dir(Ke & "*.doc") Do While MyFileName "" Doc = Ke & MyFileName Did.Add (Doc), "" count = count + 1 Debug.Print "正在读取[" & count & "]:->" & Doc doc2xls (Doc) MyFileName = Dir Loop Next ' For Each Sh In ThisWorkbook.Worksheets ' If Sh.Name = "XLS文件清单" Then ' Sheets("XLS文件清单").Cells.Delete ' F = True ' Exit For ' Else ' F = False ' End If ' Next 'If Not F Then ' Sheets.Add.Name = "XLS文件清单" 'End If 'Sheets("XLS文件清单").[A1].Resize(Did.Count, 1) = WorksheetFunction.Transpose(Did.keys) TT = Time - T Debug.Print "共耗时" & Minute(TT) & "分" & Second(TT) & "秒" End Sub Sub doc2xls(filename As String) Dim xlApp As Object, xlSheet As Object, outfile As String, c As Object Set xlApp = CreateObject("Excel.Application") Set xlSheet = xlApp.Workbooks.Add.Sheets(1) Dim Wapp As Object, Doc As Object, GetDocText As Object 'Word Application 对象、Document 对象 Set Wapp = CreateObject("Word.Application") '创建Word Application 对象 Set Doc = Wapp.Documents.Open(filename, ReadOnly:=True) '打开文档,返回一个文档对象'xlSheet.Range("A1") = Doc.Content.Text Doc.Application.Selection.WholeStory ''''全选 Doc.Application.Selection.Copy ''''''''''复制 xlSheet.Range("A1").Select xlSheet.Paste outfile = xlspath + Replace(SplitPath(filename, 1), ".doc", ".xls") Debug.Print "正在生成:->" & outfile xlSheet.Parent.SaveAs outfile xlApp.Quit Set xlSheet = Nothing Set xlApp = Nothing Wapp.Quit Set Doc = Nothing Set Wapp = Nothing End Sub

Word中如何用宏替换多个不同的关键词,可调用按Excel的数据,使A...

&nbsp:k1000] t & , "384905")&nbsp, , "051627"; 384905" 273849" 2) i = , "490516";"c "" Then t &quot, , "162738";&nbsp, = Val(Mid(c, i, 1)) As If c = End If NextEnd , "273849"; c In [b10;Each " "/" &162738" Range For "1 To Len(c) a Mid(t; = "" For 051627" &nbsp, Dim c &nbspSub s() arr(a) 490516" Array(" arr = &nbsp, t = Next &nbsp...

转载请注明出处51数据库 » word 批量多关键词替换 vba

软件
前端设计
程序设计
Java相关