ZKX's LAB

查找word表格中的文字包含在文档中的某个标题中,则超链接到这个标题,如何用VBA实现 Vba查找所有的标题

2021-04-23知识8

VBA如何遍历WORD文档中的某一级标题 使用Find方法,看看是不是快了。'样式、符合样式的当前段文本Dim wdSty$,strTxt$wdSty=\"标题 1With SelectionHomeKey unit:=wdStory,Extend:=wdMove'光标移到文档首Find.ClearFormattingFind.Style=ActiveDocument.Styles(wdSty)'设置查找文本的样式为wdSty(“标题1”)End With'循环查找文档里所有为“标题1”样式的段落,Do While Selection.Find.Execute(findtext:=\"*13\",MatchWildcards:=True,Format:=True)strTxt=Selection.Text '获取符合样式的文本'.在这里录入处理代码Selection.Move unit:=wdWord,Count:=1If Selection.MoveRight<;>;1 Then'文档尾退出Exit DoElseSelection.MoveLeftEnd IfLoop

在word中使用VBA区分标题和正文 获取标题与?文使用style?试验?代码?Sub Test()Dim i As SingleFor i=1 To ActiveDocument.BuiltInDocumentProperties(wdPropertyLines).ValueWith SelectionGoTo What:=wdGoToLine,Which:=wdGoToAbsolute,Count:=iHomeKey Unit:=wdLineEndKey Unit:=wdLine,Extend:=wdExtendEnd WithIf Selection.Style=?文\"ThenMsgBox i&\"行?文End IfIf Selection.Style=\"标题 1\"ThenMsgBox i&\"行?标题 1End IfNextEnd Sub

帮忙写个VBA,根据标题名“出厂编号”,找到列,并修改列格式 接!qq244202637msn:dhumurderor@hotmail.com代码如下,供大大分享Dim Cs As Integer '每个sheet存在的最大列数Dim f As WorkbookDim i As IntegerDim j As Integer 'sheet页的标示On Error GoTo 2000Application.Visible=FalseApplication.DisplayAlerts=FalseSet f=Workbooks.Open(ThisWorkbook.Path&\"\\处理表.xls\")'打开文件为当前目录加文件名称Debug.Print\"页数\"&f.Sheets.CountFor j=1 To f.Sheets.CountIf f.Sheets(j).Visible=True ThenDebug.Print\"第\"&j&\"页;f.Sheets(j).Namef.Sheets(j).SelectCs=Range(\"IV1\").End(xlToLeft).Column '数据的最大列数'对该页做单元格循环处理,如果找到出厂编号,则选中该单元格,并将其格式化For i=1 To CsDebug.Print i&Range(\"A1\").Cells(1,i).Value&\":\"&Range(\"A2\").Cells(1,i).ValueIf Range(\"A1\").Cells(1,i).Value=\"出厂编号\"ThenRange(\"A2\").Cells(1,i).SelectSelection.NumberFormatLocal=\"@Exit ForEnd IfNextIf iDebug.Print\"第\"&j&\"页所在位置\"&iElse:Debug.Print\"第\"&j&\"页没有End IfElse:Debug.Print\"第\"&j&\"页被隐藏End IfDebug.Print\"-Nextf.Sheets(1).Selectf。.

随机阅读

qrcode
访问手机版