Word宏是一種自動化程序,可幫助用戶在Word中自動執行常見的重複任務。Word宏可以在Word中自動完成許多任務,包括創建自定義工具欄、執行常見編輯任務、應用格式、創建打印模板等。本文將從多個方面介紹Word宏的編輯和設置方法,為讀者提供全面的參考。
一、Word宏怎麼編輯和設置打印模板
1、進入“視圖”選項卡,單擊“頁面布局”按鈕。
Sub CreateMacro()
' CreateMacro 宏
With ActiveDocument.PageSetup
.TopMargin = 50
.BottomMargin = 50
.LeftMargin = 50
.RightMargin = 50
.FooterDistance = 0
.HeaderDistance = 36
.PageWidth = 595
.PageHeight = 842
End With
End Sub
2、用代碼編輯打印模板,以便自定義單獨頁面的大小、旋轉以及頁面方向。
Sub CustomPage()
' CustomPage 宏
With ActiveDocument.PageSetup
.PageWidth = CentimetersToPoints(25.5)
.PageHeight = CentimetersToPoints(16.5)
.Orientation = wdOrientLandscape
.DifferentFirstPageHeaderFooter = True
.LeftMargin = CentimetersToPoints(1.27)
.RightMargin = CentimetersToPoints(1.27)
.TopMargin = CentimetersToPoints(2.54)
.BottomMargin = CentimetersToPoints(2.54)
End With
End Sub
3、打開“開發人員”選項卡,單擊“宏”按鈕,在彈出的對話框中選擇相應的宏進行運行。
二、Word宏怎麼編輯和設置
1、使用Word宏可以自動完成一系列編輯任務,如自動修剪、複製、粘貼、格式插入等。
Sub FormatText()
' FormatText 宏
Selection.TypeText Text:="Hello World!"
Selection.Font.Bold = True
Selection.Font.Italic = True
Selection.Font.Name = "Calibri"
Selection.Font.Size = 16
End Sub
2、可以設置宏以根據所選內容調整大小和坐標。
Sub AutoFit()
' AutoFit 宏
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = 100
End Sub
3、也可以設置宏以創建自定義工具欄和按鈕,以便可以重複使用。
Sub CreateToolbar()
' CreateToolbar 宏
Set NewToolbar = CommandBars.Add(Name:="Custom Toolbar", Position:=msoBarFloating, _
Temporary:=True)
With NewToolbar
.Visible = True
.Controls.Add(Type:=msoControlButton, ID:=3).FaceId = 22
.Controls.Add(Type:=msoControlButton, ID:=12).Caption = "Save As"
.Controls.Add(Type:=msoControlButton, ID:=13).Caption = "Open"
End With
End Sub
三、Word怎麼編輯目錄格式
1、在Word中打開“引用”選項卡,單擊“目錄”按鈕。
Sub CreateTableOfContents()
' CreateTableOfContents 宏
With ActiveDocument
.TablesOfContents.Add Range:=Range(Start:=0, End:=0), _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=True, _
UpperHeadingLevel:=1, _
LowerHeadingLevel:=3
End With
End Sub
2、使用“目錄”的選項掛鈎,使用不同的樣式格式化目錄的外觀。
Sub TableOfContentsStyle()
' TableOfContentsStyle 宏
ActiveDocument.TableOfContents.TabLeader = wdTabLeaderDots
ActiveDocument.TableOfContents.UseFields = False
ActiveDocument.TableOfContents.HeadingStyles(wdTOCHeading1).Range.Style = "Heading 1"
ActiveDocument.TableOfContents.HeadingStyles(wdTOCHeading2).Range.Style = "Heading 2"
ActiveDocument.TableOfContents.HeadingStyles(wdTOCHeading3).Range.Style = "Heading 3"
End Sub
3、可以設置目錄以根據所選內容自動調整大小和位置。
Sub AutoFitTableOfContents()
' AutoFitTableOfContents 宏
With ActiveDocument.TablesOfContents(1)
.TabLeader = wdTabLeaderDots
.UseFields = False
.HeadingStyles(wdTOCHeading1).Range.Style = "Heading 1"
.HeadingStyles(wdTOCHeading2).Range.Style = "Heading 2"
.HeadingStyles(wdTOCHeading3).Range.Style = "Heading 3"
End With
End Sub
四、Word宏的功能怎麼設置
1、使用宏可以自動創建新文本框並設置其樣式、大小和位置。
Sub CreateTextbox()
' CreateTextbox 宏
Dim myTextbox As Shape
With ActiveDocument
Set myTextbox = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=50, Top:=50, Width:=100, Height:=50)
With myTextbox.TextFrame
.TextRange.Text = "Hello, World"
.HorizontalAnchor = msoAnchorCenter
.VerticalAnchor = msoAnchorMiddle
End With
With myTextbox.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 255)
.Weight = 1
End With
End With
End Sub
2、可以設置宏以創建自定義菜單和選項卡。
Sub CreateCustomMenu()
' CreateCustomMenu 宏
Application.CommandBars("Menu Bar").Controls _
.Add(Type:=msoControlPopup, Temporary:=True).Caption = "My Menu"
End Sub
3、還可以設置宏以強制執行特定的文本格式屬性。
Sub ForceFormat()
' ForceFormat 宏
With Selection.Font
.Name = "Arial"
.Bold = True
.Size = 18
.Color = RGB(255, 0, 0)
End With
End Sub
五、Word編輯目錄怎麼設置
1、進入“引用”選項卡,單擊“目錄”按鈕,在彈出的對話框中選擇相應的目錄類型。
Sub CreateTableOfContents() ' CreateTableOfContents 宏 ActiveDocument.TablesOfContents.Add Range:=Selection.Range, _ RightAlignPageNumbers:=True, UseHeadingStyles:=True, _ UpperHeadingLevel:=1, LowerHeadingLevel:=3, _ IncludePageNumbers:=True, AddedStyles:="", _ UseHyperlinks:=True, HidePageNumbersInWeb:=True, _ UseOutlineLevels:=False End Sub
2、使用“目錄屬性”選項卡設置字體、顏色、大小等屬性。
Sub SetTableOfContentsProperties()
' SetTableOfContentsProperties 宏
With Selection.Range
.Font.Name = "Georgia"
.Font.Size = 14
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.ParagraphFormat.SpaceBefore = 6
.ParagraphFormat.SpaceAfter = 6
End With
End Sub
3、可以使用宏設置左側空白區域的寬度,從而使目錄看起來更美觀。
Sub SetTableOfContentsIndentation()
' SetTableOfContentsIndentation 宏
With ActiveDocument.TablesOfContents(1)
.TabLeader = wdTabLeaderDots
.UseFields = False
.HeadingStyles(wdTOCHeading1).Range.Style = "Heading 1"
.HeadingStyles(wdTOCHeading2).Range.Style = "Heading 2"
.HeadingStyles(wdTOCHeading3).Range.Style = "Heading 3"
.TabIndent = CentimetersToPoints(1)
End With
End Sub
六、Word如何設置編輯框
1、單擊“文件”選項卡,然後單擊“選項”按鈕,在彈出的對話框中單擊“自定義功能區”。
Sub CreateUserForm()
' CreateUserForm 宏
Dim myDialog As UserForm1
Set myDialog = New UserForm1
myDialog.Show
End Sub
2、使用編輯框工具創建新的編輯框,設置其大小和位置。
Sub CreateTextBox()
' CreateTextBox 宏
Dim myTextBox As TextBox
Set myTextBox = ActiveDocument.ContentControls.Add(wdContentControlRichText)
With myTextBox
.Title = "Enter Text Here"
.Width = CentimetersToPoints(8)
.Height = CentimetersToPoints(1.5)
.Left = CentimetersToPoints(1)
.Top = CentimetersToPoints(2)
End With
End Sub
3、可以設置宏以強制執行特定的編輯框格式屬性,例如字體、顏色和大小。
Sub FormatTextBox()
' FormatTextBox 宏
With ActiveDocument.ContentControls(1).Range.Font
.Name = "Georgia"
.Size = 14
.Color = RGB(255, 0, 0)
End With
End Sub
七、Word宏怎麼設置
1、可以設置宏以自定義“快捷鍵”,方便用戶快速執行常見任務。
Sub CustomShortcutKeys()
' CustomShortcutKeys 宏
Application.CustomizationContext = ActiveDocument.AttachedTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, wdKeyF1), _
KeyCode2:=wdKeyBackSingleQuote, Command:="CreateTextbox"
End Sub
2、可以設置宏將自定義功能區添加到“快速訪問工具欄”,以便在不同的文檔中重複使用。
Sub AddToQuickAccessToolbar()
' AddToQuickAccessToolbar 宏
Application.CustomizationContext = ActiveDocument.AttachedTemplate
Dim myCommand As CommandBarButton
Set myCommand = Application.CommandBars("Quick Access Toolbar").Controls _
.Add(msoControlButton)
With myCommand
.Caption = "Create Textbox"
.Style = msoButtonIconAndCaption
.FaceId = 123
.Tag = "CreateTextbox"
.OnAction = "CreateTextbox"
End With
End Sub
3、也可以設置宏以自定義文檔中的特定樣式和格式。
Sub CustomizeDocumentStyle()
' CustomizeDocumentStyle 宏
With ActiveDocument.Styles("Heading 1").Font
.Size = 16
.Bold = True
.Color = RGB(0, 0, 255)
End With
End Sub
總結
本文詳細介紹了Word宏的編輯和設置方法。從多個方面介紹了Word宏編輯和設置的相關操作,包括打印模板、編輯和設置、目錄格式、功能設置、編輯目錄設置和設置編輯框。除此之外,本文還給出了相應的代碼示例,方便讀者快速實踐。在使用Word時,我們可以根據實際需要自定義宏以簡化我們的工作流程,提高數據處理效率。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/285228.html
微信掃一掃
支付寶掃一掃