Sub glkCurrentDocPageSetup()
Dim glkDoc As Document '定義變量
Set glkDoc = Application.ActiveDocument '設置為當前文檔
With glkDoc '設置文檔參數
With .PageSetup '設置【頁面設置】參數
.Orientation = wdOrientPortrait '頁面方向為縱向
.TopMargin = CentimetersToPoints(3) '上邊距為3cm
.BottomMargin = CentimetersToPoints(3) '下邊距為3cm
.LeftMargin = CentimetersToPoints(2.6) '左邊距為2.6cm
.RightMargin = CentimetersToPoints(2.3) '右邊距為2.6com
.Gutter = CentimetersToPoints(0) '裝訂線0cm
.HeaderDistance = CentimetersToPoints(1.5) '頁眉1.5cm
.FooterDistance = CentimetersToPoints(2) '頁腳2cm
.PageWidth = CentimetersToPoints(21) '紙張寬21cm
.PageHeight = CentimetersToPoints(29.7) '紙張高29.7cm
.SectionStart = wdSectionNewPage '節的起始位置:新建頁
.OddAndEvenPagesHeaderFooter = False '不勾選“奇偶頁不同”
.DifferentFirstPageHeaderFooter = False '不勾選“首頁不同”
.VerticalAlignment = wdAlignVerticalTop '頁面垂直對齊方式為“頂端對齊”
.SuppressEndnotes = False '不隱藏尾註
.MirrorMargins = False '不設置首頁的內外邊距
.BookFoldRevPrinting = False '不設置手動雙面打印
.BookFoldPrintingSheets = 1 '默認打印份數為1
.GutterPos = wdGutterPosLeft '裝訂線位於左側
.LayoutMode = wdLayoutModeLineGrid '版式模式為“只指定行網格”
End With '結束【頁面設置】參數設置
With .Content.ParagraphFormat '段落格式設置
.LeftIndent = CentimetersToPoints(0) '左縮進0cm
.RightIndent = CentimetersToPoints(0) '右縮進0cm
.SpaceBefore = 0 '段前間距0cm
.SpaceBeforeAuto = False '段前間距不設為“自動”
.SpaceAfter = 0 '段後間距0cm
.SpaceAfterAuto = False '段後間距不設為“自動”
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing = 30 '行距30磅
.Alignment = wdAlignParagraphJustify '段落設置為兩端對齊
.WidowControl = False '不勾選“孤行控制”
.KeepWithNext = False '不勾選“與下段同頁”
.KeepTogether = False '不勾選“段中不分頁”
.PageBreakBefore = False '不勾選“段前同頁”
.NoLineNumber = False '不勾選“取消行號”
.Hyphenation = True '不勾選“允許西文在單詞中間換行”
.FirstLineIndent = CentimetersToPoints(2) '首行縮進2cm
.OutlineLevel = wdOutlineLevelBodyText '大綱級別為“正文文本”
.CharacterUnitLeftIndent = 0 '段落左縮進0cm
.CharacterUnitRightIndent = 0 '段落右縮進0cm
.CharacterUnitFirstLineIndent = 0 '特殊格式為“無”
.LineUnitBefore = 0 '段前間距為0
.LineUnitAfter = 0 '段後間距為0
.AutoAdjustRightIndent = True '自動調整段落的右縮進
.DisableLineHeightGrid = False '勾選“如果定義了文檔網格,則對齊網格”,即指定段落中的字符與行網格對齊
.FarEastLineBreakControl = True '將東亞語言文字的換行規則應用於指定的段落
.WordWrap = True '在指定段落或文本框的西文單詞中間斷字換行
.HangingPunctuation = True '指定段落中的標點將可以溢出邊界
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True '自動在指定段落的中文文字和拉丁文字之間添加空格。
.AddSpaceBetweenFarEastAndDigit = True '自動在指定段落中的中文文字與數字之間添加空格
.BaseLineAlignment = wdBaselineAlignAuto '自動調整基線字體對齊方式
End With''''''''''新增部分
With .Styles("標題 1").Font
.Color = wdColorBlack
.Bold = False '標題不再加粗
.Size = 22 '三號
.Name = "宋體"
End With
With .Styles("標題 2").Font
.Color = wdColorBlack
.Bold = False '黑體一般不再加粗
.Size = 16 '三號
.Name = "楷體"
End With
With .Styles("正文").Font '設置正文普通文字格式
.Color = wdColorBlack
.Bold = False
.Size = 10
.Name = "宋體"
End With
End With '結束文檔參數設置
End Sub
Sub 表格處理()
'功能:光標在表格中處理當前表格;否則處理所有表格!
Application.ScreenUpdating = False '關閉屏幕刷新
Application.DisplayAlerts = False '關閉提示
On Error Resume Next '忽略錯誤
'***************************************************************************
Dim mytable As Table, i As Long
If Selection.Information(wdWithInTable) = True Then i = 1
For Each mytable In ActiveDocument.Tables
If i = 1 Then Set mytable = Selection.Tables(1)
With mytable
'取消底色
.Shading.ForegroundPatternColor = wdColorAutomatic
.Shading.BackgroundPatternColor = wdColorAutomatic
Options.DefaultHighlightColorIndex = wdNoHighlight
.Range.HighlightColorIndex = wdNoHighlight
.Style = "表格主題"
'單元格邊距
.TopPadding = PixelsToPoints(0, True) '設置上邊距為0
.BottomPadding = PixelsToPoints(0, True) '設置下邊距為0
.LeftPadding = PixelsToPoints(0, True) '設置左邊距為0
.RightPadding = PixelsToPoints(0, True) '設置右邊距為0
.Spacing = PixelsToPoints(0, True) '允許單元格間距為0
.AllowPageBreaks = True '允許斷頁
'.AllowAutoFit = True '允許自動重調尺寸
'設置邊框
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleThinThickMedGap
.Borders(wdBorderTop).LineWidth = wdLineWidth225pt
.Borders(wdBorderBottom).LineStyle = wdLineStyleThickThinMedGap
.Borders(wdBorderBottom).LineWidth = wdLineWidth225pt
With .Rows
.WrapAroundText = False '取消文字環繞
.Alignment = wdAlignRowCenter '表水平居中 wdAlignRowLeft '左對齊
.AllowBreakAcrossPages = False '不允許行斷頁
.HeightRule = wdRowHeightExactly '行高設為最小值 wdRowHeightAuto '行高設為自動
.Height = CentimetersToPoints(0) '上面縮進量為0
.LeftIndent = CentimetersToPoints(0) '左面縮進量為0
End With
With .Range
With .Font '字體格式
.Name = "宋體"
.Name = "Times New Roman"
.Color = wdColorAutomatic '自動字體顏色
.Size = 12
.Kerning = 0
.DisableCharacterSpaceGrid = True
End With
With .ParagraphFormat '段落格式
.CharacterUnitFirstLineIndent = 0 '取消首行縮進
.FirstLineIndent = CentimetersToPoints(0) '取消首行縮進
.LineSpacingRule = wdLineSpaceSingle '單倍行距 wdLineSpaceExactly '行距固定值
'.LineSpacing = 20 '設置行間距為20磅,配合行距固定值
.Alignment = wdAlignParagraphCenter '單元格水平居中
.AutoAdjustRightIndent = False
.DisableLineHeightGrid = True
End With
.Cells.VerticalAlignment = wdCellAlignVerticalCenter '單元格垂直居中
End With
'設置首行格式
.Cell(1, 1).Select ' 選中第一個單元格
With Selection
.SelectRow '選中當前行
Selection.Rows.HeadingFormat = wdToggle '自動標題行重複
.Range.Font.Bold = True '表頭加粗黑體
.Shading.ForegroundPatternColor = wdColorAutomatic '首行自動顏色
.Shading.BackgroundPatternColor = -603923969 '首行底紋填充
End With
'自動調整表格
.Columns.PreferredWidthType = wdPreferredWidthAuto
.AutoFitBehavior (wdAutoFitContent) '根據內容調整表格
.AutoFitBehavior (wdAutoFitWindow) '根據窗口調整表格
End With
If i = 1 Then Exit For
Next
'***************************************************************************
Err.Clear: On Error GoTo 0 '恢復錯誤捕捉
Application.DisplayAlerts = True '開啓提示
Application.ScreenUpdating = True '開啓屏幕刷新
End Sub'設置圖片大小
Dim Shap As InlineShapeFor Each Shap In ActiveDocument.InlineShapes
If Shap.Type = wdInlineShapePicture Then
Shap.LockAspectRatio = msoFalse '不鎖定縱橫比
Shap.Width = CentimetersToPoints(10) '寬10CM
Shap.Height = CentimetersToPoints(7) '高7CM
End If
Next
'設置頁碼
Sub sutAddPageNum1()
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set rng = .Range
rng.Text = "第 "
rng.Font.Size = 16 '三號
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldPage, "Page"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " 頁 / 共 "
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldNumPages, "Pages"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " 頁 "
.Range.Fields.Update
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
End Sub
本文章為轉載內容,我們尊重原作者對文章享有的著作權。如有內容錯誤或侵權問題,歡迎原作者聯繫我們進行內容更正或刪除文章。