導航:首頁 > 文件教程 > vbaword標題編號

vbaword標題編號

發布時間:2025-03-30 03:36:01

wordVBA將文檔中特定字元設置為上標或下標

Option Explicit
Sub SetSuperscriptAndSubscript(ByVal PrefixChr As String, ByVal SetChr As String, Optional ByVal SuperscriptMode As Boolean = True)
'程序功能:設置文檔中特定字元為上標或下標。
'參數說明:
'PrefixChr:必選參數,要設置為上、下標字元之前的字元;
'SetChr:必選參數,要設置為上、下標的字元;
'SuperscriptMode:可選參數,設置為 True 表示將 SetChr 設置為上標,設置為 False 表示將 SetChr 設置為下標,默認為 True。
'舉例說明:
'我們要將文檔中所有的「m3/s」中的「3」設置為上標,可通過下面這一行代碼調用本程序完成:
'SetSuperscriptAndSubscript "M","3" '這里設置上標,可省略第三個參數。
Selection.Start = ActiveDocument.Paragraphs(1).Range.Start '將游標定位至活動文檔第一段落段首的位置
Selection.Collapse wdCollapseStart '折疊至起始位置
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = PrefixChr & SetChr
.Replacement.Text = "^&"
If SuperscriptMode Then .Replacement.Font.Superscript = True Else .Replacement.Font.Subscript = True
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Replacement.ClearFormatting
.Text = PrefixChr
If SuperscriptMode Then .Font.Superscript = True Else .Font.Subscript = True
.Replacement.Text = "^&"
If SuperscriptMode Then .Replacement.Font.Superscript = False Else .Replacement.Font.Subscript = False
.Execute Replace:=wdReplaceAll
End With
End Sub

❷ 在word中使用VBA區分標題和正文

獲取標題與正文使用style。試驗一下如下代碼。

SubTest()
DimiAsSingle
Fori=1ToActiveDocument.BuiltInDocumentProperties(wdPropertyLines).Value
WithSelection
.GoToWhat:=wdGoToLine,Which:=wdGoToAbsolute,Count:=i
.HomeKeyUnit:=wdLine
.EndKeyUnit:=wdLine,Extend:=wdExtend
EndWith
IfSelection.Style="正文"Then
MsgBoxi&"行是正文"
EndIf
IfSelection.Style="標題1"Then
MsgBoxi&"行是標題1"
EndIf
Next

EndSub

❸ word編號多級列表怎麼設置

當文中存在多級大綱級別的時候,應用多級編號才會有效,應用大綱級別的文字,在左邊會有提示,從圖中看,你這個並未應用大綱級別,所以多級編號未應用。

那麼如何批量修改成多級編號呢,一般來說有替換法、自動編號法、excel法、vba等,下面我就你圖4的情況如何加上自動編號進行大型講解攻略。

首先我先將你的文字整理復制到一個word文檔中做演示:

❹ VBA如何遍歷WORD文檔中的某一級標題

使用Find方法,看看是不是快了。
'樣式、符合樣式的當前段文本
Dim wdSty$, strTxt$
wdSty = "標題 1"
With Selection
.HomeKey unit:=wdStory, Extend:=wdMove'游標移到文檔首
.Find.ClearFormatting
.Find.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:=1
If Selection.MoveRight <> 1 Then'文檔尾退出
Exit Do
Else
Selection.MoveLeft
End If
Loop

❺ word vba如何批量復製表格並編號

下面這段代碼是實現將excel表格插入到指定word模板的指定位置。可以參考一下。

Sub 插入表格()
Dim SS As String
Dim wdoc As New Word.Application
Dim 當前路徑, 導出路徑文件名, i, j
Dim Str1, Str2, Str3
Dim tarr(1 To 100, 1 To 3)
Dim filepathname As String
當前路徑 = ThisWorkbook.Path

最後行號 = Sheets("數字表格").Range("B30").End(xlUp).Row
判斷 = 0
' 導出文件名 = "報告作品.doc"
filepathname = 當前路徑 & "\" & Tfile
If Dir(filepathname) = "" Then
'文件不存在
FileCopy 當前路徑 & "\" & Sfile, 當前路徑 & "\" & Tfile
End If
Sheets("數字表格").Select
For i = KShh To 最後行號
tarr(i - KShh + 1, 1) = Sheets("數字表格").Cells(i, 1)
tarr(i - KShh + 1, 2) = Sheets("數字表格").Cells(i, 2)
tarr(i - KShh + 1, 3) = Sheets("數字表格").Cells(i, 3)
Next i
j = i - KShh '記錄需替換文本個數
導出路徑文件名 = 當前路徑 & "\" & Tfile
With wdoc '打開word文檔
.Documents.Open 導出路徑文件名
.Visible = True
End With
For i = 1 To j
Str1 = tarr(i, 1)
Str2 = tarr(i, 2)
Str3 = tarr(i, 3)
Range(Str3).Select
Application.CutCopyMode = False
Selection.Copy

With wdoc
.Selection.HomeKey Unit:=wdStory '游標置於文件首
If .Selection.Find.Execute(Str1) Then '查找到指定字元串
.Selection.Text = "" '替換字元串
.Selection.PasteExcelTable False, False, False '粘貼為表格
.Selection.WholeStory
.Selection.Font.Size = 12
With .Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
.Selection.Tables(1).PreferredWidthType = 3
.Selection.Tables(1).PreferredWidth = .CentimetersToPoints(15)
End If
' wdoc.Documents.Save
' wdoc.Quit
' Set wdoc = Nothing
End With
Next i
With wdoc '存檔後關閉WORD文檔
wdoc.Documents.Save
wdoc.Quit
Set wdoc = Nothing
End With
Sheets("首頁").Select
End Sub

閱讀全文

與vbaword標題編號相關的資料

熱點內容
三星471如何線下編程 瀏覽:342
eclipse怎麼導入android程序 瀏覽:221
lol手機app有哪些 瀏覽:49
第一次編程怎麼打 瀏覽:632
北京金網時代系統集成網路技術有限公司 瀏覽:962
收藏的文件夾有哪些 瀏覽:846
識別物品並分類怎麼編程 瀏覽:126
word頁邊距單位 瀏覽:503
iphone5s黑名單 瀏覽:174
手機js文件是什麼 瀏覽:825
編程圍棋火花思維學哪個好 瀏覽:462
word頁邊距右邊大 瀏覽:821
65版本的qq下載 瀏覽:360
知道網站ip怎麼攻擊 瀏覽:506
iphone拆機圖 瀏覽:834
溫州編程培訓班哪個好 瀏覽:351
能讓word文檔讀出聲音的文件 瀏覽:145
撿aPP怎麼登錄 瀏覽:628
英語不好適合學哪個編程 瀏覽:397
skip文件如何用Word打開 瀏覽:988

友情鏈接