当前位置:网站首页>VBA format word (page, paragraph, table, picture)
VBA format word (page, paragraph, table, picture)
2022-06-13 08:47:00 【variation8】
Sub glkCurrentDocPageSetup()
Dim glkDoc As Document ' Defining variables
Set glkDoc = Application.ActiveDocument ' Set as current document
With glkDoc ' Set document parameters
With .PageSetup ' Set up 【 Page setup 】 Parameters
.Orientation = wdOrientPortrait ' Page orientation is vertical
.TopMargin = CentimetersToPoints(3) ' The top margin is 3cm
.BottomMargin = CentimetersToPoints(3) ' The bottom margin is 3cm
.LeftMargin = CentimetersToPoints(2.6) ' The left margin for 2.6cm
.RightMargin = CentimetersToPoints(2.3) ' The right margin is 2.6com
.Gutter = CentimetersToPoints(0) ' The binding line 0cm
.HeaderDistance = CentimetersToPoints(1.5) ' header 1.5cm
.FooterDistance = CentimetersToPoints(2) ' The footer 2cm
.PageWidth = CentimetersToPoints(21) ' The paper sheet is wide 21cm
.PageHeight = CentimetersToPoints(29.7) ' Paper height 29.7cm
.SectionStart = wdSectionNewPage ' The starting position of the section : new page
.OddAndEvenPagesHeaderFooter = False ' Don't check “ The odd and even pages are different ”
.DifferentFirstPageHeaderFooter = False ' Don't check “ Different Homepage ”
.VerticalAlignment = wdAlignVerticalTop ' The vertical alignment of the page is “ Top alignment ”
.SuppressEndnotes = False ' Don't hide endnotes
.MirrorMargins = False ' Do not set the inside and outside margins of the home page
.BookFoldRevPrinting = False ' Do not set manual duplex
.BookFoldPrintingSheets = 1 ' The default number of prints is 1
.GutterPos = wdGutterPosLeft ' The binding line is on the left
.LayoutMode = wdLayoutModeLineGrid ' The layout mode is “ Specify only the row grid ”
End With ' end 【 Page setup 】 Parameter setting
With .Content.ParagraphFormat ' Paragraph formatting
.LeftIndent = CentimetersToPoints(0) ' Left 0cm
.RightIndent = CentimetersToPoints(0) ' Indent right 0cm
.SpaceBefore = 0 ' Pre segment spacing 0cm
.SpaceBeforeAuto = False ' The spacing before the segment is not set to “ Automatically ”
.SpaceAfter = 0 ' The interval after the segment 0cm
.SpaceAfterAuto = False ' The spacing after the segment is not set to “ Automatically ”
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing = 30 ' row spacing 30 pounds
.Alignment = wdAlignParagraphJustify ' Set paragraph to align
.WidowControl = False ' Don't check “ Solitary control ”
.KeepWithNext = False ' Don't check “ Same page as the next paragraph ”
.KeepTogether = False ' Don't check “ There is no paging in the segment ”
.PageBreakBefore = False ' Don't check “ Same page before paragraph ”
.NoLineNumber = False ' Don't check “ Cancel the line Numbers ”
.Hyphenation = True ' Don't check “ Allow Western words to wrap between words ”
.FirstLineIndent = CentimetersToPoints(2) ' The first line indentation 2cm
.OutlineLevel = wdOutlineLevelBodyText ' The outline level is “ Body text ”
.CharacterUnitLeftIndent = 0 ' Paragraph left indent 0cm
.CharacterUnitRightIndent = 0 ' Paragraph right indent 0cm
.CharacterUnitFirstLineIndent = 0 ' The special format is “ nothing ”
.LineUnitBefore = 0 ' The spacing before the segment is 0
.LineUnitAfter = 0 ' The interval after the segment is 0
.AutoAdjustRightIndent = True ' Automatically adjust the right indent of paragraphs
.DisableLineHeightGrid = False ' Check “ If a document grid is defined , Then align the grid ”, That is, the characters in the specified paragraph are aligned with the line grid
.FarEastLineBreakControl = True ' Apply the line break rule of East Asian language text to the specified paragraph
.WordWrap = True ' Break a line in the middle of a western word in a specified paragraph or text box
.HangingPunctuation = True ' The punctuation in the specified paragraph will overflow the boundary
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True ' Automatically add a space between the Chinese and Latin text of the specified paragraph .
.AddSpaceBetweenFarEastAndDigit = True ' Automatically add a space between Chinese text and numbers in the specified paragraph
.BaseLineAlignment = wdBaselineAlignAuto ' Automatically adjust baseline font alignment
End With
'''''''''' What's new
With .Styles(" title 1").Font
.Color = wdColorBlack
.Bold = False ' The title is no longer bold
.Size = 22 ' No. 3
.Name = " Song style "
End With
With .Styles(" title 2").Font
.Color = wdColorBlack
.Bold = False ' Boldface is generally no longer bold
.Size = 16 ' No. 3
.Name = " Regular script "
End With
With .Styles(" Text ").Font ' Set the normal text format of the body
.Color = wdColorBlack
.Bold = False
.Size = 10
.Name = " Song style "
End With
End With ' End document parameter setting
End Sub
Sub Form handling ()
' function : The cursor processes the current table in the table ; Otherwise, process all tables !
Application.ScreenUpdating = False ' Turn off screen refresh
Application.DisplayAlerts = False ' Turn off the prompt
On Error Resume Next ' Ignore mistakes
'***************************************************************************
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
' Cancel the background color
.Shading.ForegroundPatternColor = wdColorAutomatic
.Shading.BackgroundPatternColor = wdColorAutomatic
Options.DefaultHighlightColorIndex = wdNoHighlight
.Range.HighlightColorIndex = wdNoHighlight
.Style = " Table subject "
' Cell margins
.TopPadding = PixelsToPoints(0, True) ' Set the top margin to 0
.BottomPadding = PixelsToPoints(0, True) ' Set the bottom margin to 0
.LeftPadding = PixelsToPoints(0, True) ' Set the left margin to 0
.RightPadding = PixelsToPoints(0, True) ' Set the right margin to 0
.Spacing = PixelsToPoints(0, True) ' Allow cell spacing of 0
.AllowPageBreaks = True ' Allow page breaks
'.AllowAutoFit = True ' Allow automatic resizing
' Set borders
.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 ' Cancel text wrapping
.Alignment = wdAlignRowCenter ' The table is horizontally centered wdAlignRowLeft ' Align left
.AllowBreakAcrossPages = False ' Line breaks are not allowed
.HeightRule = wdRowHeightExactly ' Set the row height to the minimum wdRowHeightAuto ' The row height is set to automatic
.Height = CentimetersToPoints(0) ' The top indent is 0
.LeftIndent = CentimetersToPoints(0) ' The left indent is 0
End With
With .Range
With .Font ' Font format
.Name = " Song style "
.Name = "Times New Roman"
.Color = wdColorAutomatic ' Automatic font color
.Size = 12
.Kerning = 0
.DisableCharacterSpaceGrid = True
End With
With .ParagraphFormat ' Paragraph format
.CharacterUnitFirstLineIndent = 0 ' Cancel the first line indent
.FirstLineIndent = CentimetersToPoints(0) ' Cancel the first line indent
.LineSpacingRule = wdLineSpaceSingle ' Single spaced wdLineSpaceExactly ' Fixed line spacing
'.LineSpacing = 20 ' Set the line spacing to 20 pounds , Match the fixed value of line spacing
.Alignment = wdAlignParagraphCenter ' Center the cell horizontally
.AutoAdjustRightIndent = False
.DisableLineHeightGrid = True
End With
.Cells.VerticalAlignment = wdCellAlignVerticalCenter ' The cell is vertically centered
End With
' Format the first line
.Cell(1, 1).Select ' Select the first cell
With Selection
.SelectRow ' Select the current line
Selection.Rows.HeadingFormat = wdToggle ' Auto header row repeat
.Range.Font.Bold = True ' The header is bold
.Shading.ForegroundPatternColor = wdColorAutomatic ' First line auto color
.Shading.BackgroundPatternColor = -603923969 ' First line shading fill
End With
' Auto adjust table
.Columns.PreferredWidthType = wdPreferredWidthAuto
.AutoFitBehavior (wdAutoFitContent) ' Adjust the table according to the content
.AutoFitBehavior (wdAutoFitWindow) ' Adjust the table according to the window
End With
If i = 1 Then Exit For
Next
'***************************************************************************
Err.Clear: On Error GoTo 0 ' Restore error capture
Application.DisplayAlerts = True ' Open prompt
Application.ScreenUpdating = True ' Turn on screen refresh
End Sub
' Set picture size
Dim Shap As InlineShape
For Each Shap In ActiveDocument.InlineShapes
If Shap.Type = wdInlineShapePicture Then
Shap.LockAspectRatio = msoFalse ' Don't lock aspect ratio
Shap.Width = CentimetersToPoints(10) ' wide 10CM
Shap.Height = CentimetersToPoints(7) ' high 7CM
End If
Next
' Set page number
Sub sutAddPageNum1()
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set rng = .Range
rng.Text = " The first "
rng.Font.Size = 16 ' No. 3
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldPage, "Page"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " page / common "
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldNumPages, "Pages"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " page "
.Range.Fields.Update
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
End Sub
边栏推荐
- Taobao commodity sales interface / Taobao commodity sales monitoring interface / cumulative commodity sales interface
- How does jupyter notebook directly output the values of multiple variables after running?
- JS to download files in batches
- 1. preliminary understanding of Express
- Object array de encapsulation
- Paging query template of Oracle
- JS wrapper object
- 浅析Visual Studio 使用
- redis
- 8、 JS data type conversion
猜你喜欢
redis.exceptions.ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
DIY UAV (anonymous controller p2+f330 rack)
Process and scheduled task management
Centering problem - the width and height of child elements are known
0. Quelques doutes au sujet de SolidWorks
Uni app essay
How app inventor accesses resource files in assets directory
0.一些自己初學Solidworks的疑惑
顺时针打印个数组
MySQL sorts according to the specified order of the specified fields
随机推荐
Sky background map, navigation page lovefanfan top
Disk management and disk partition operation
ES6 module import / export summary
File upload JS
Browser render passes
Form exercise 2
DHCP principle and configuration
Input prohibit copy and paste
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]
Buuctf web (V)
CentOS installing MySQL and setting up remote access
2020-12-28
3、 JS notes
情绪处理技巧
5、 Constant, variable
Guidance process and service control
Deploy Yum warehouse and NFS shared services
Batch package and download Alibaba OSS files
Diversified tables through TL table row consolidation
How does jupyter notebook directly output the values of multiple variables after running?