word添加c语言代码,为Word中c代码添加行号

这段VBA代码用于在Word中设置表格背景颜色为morning配色,RGB(229,229,229),并创建代码行号。它清除原有段落底纹,设置段落格式,以及调整表格边框和宽度。同时,代码会为每个段落插入行号,并在右侧显示相应行数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sub 设置代码行号()

'

' 背景色为morning的配色方案,RGB为(229,229,229)

Dim codeLineNumber As Integer

With Selection.Tables(1)

With .Shading

.Texture = wdTextureNone

.ForegroundPatternColor = wdColorAutomatic

End With

.Borders(wdBorderLeft).LineStyle = wdLineStyleNone

.Borders(wdBorderRight).LineStyle = wdLineStyleNone

.Borders(wdBorderTop).LineStyle = wdLineStyleNone

.Borders(wdBorderBottom).LineStyle = wdLineStyleNone

.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone

.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone

.Borders.Shadow = False

.Range.HighlightColorIndex = wdNoHighlight

.Columns(1).Shading.BackgroundPatternColor = wdColorGray20

.Columns(1).Width = 25

.Columns(2).Shading.BackgroundPatternColor = wdColorGray05

.Columns(2).Width = 400

End With

With Options

.DefaultBorderLineStyle = wdLineStyleSingle

.DefaultBorderLineWidth = wdLineWidth050pt

.DefaultBorderColor = wdColorAutomatic

End With

' 段落无首行缩进,行间距为固定值12磅

With Selection.ParagraphFormat

.LeftIndent = CentimetersToPoints(0)

.RightIndent = CentimetersToPoints(0)

.SpaceBefore = 0

.SpaceBeforeAuto = False

.SpaceAfter = 0

.SpaceAfterAuto = False

.LineSpacingRule = wdLineSpaceExactly

.LineSpacing = 14

.KeepWithNext = False

.KeepTogether = False

.PageBreakBefore = False

.NoLineNumber = False

.Hyphenation = True

.FirstLineIndent = CentimetersToPoints(0)

.OutlineLevel = wdOutlineLevelBodyText

.CharacterUnitLeftIndent = 0

.CharacterUnitRightIndent = 0

.CharacterUnitFirstLineIndent = 0

.LineUnitBefore = 0

.LineUnitAfter = 0

.MirrorIndents = False

.TextboxTightWrap = wdTightNone

.AutoAdjustRightIndent = True

.DisableLineHeightGrid = False

.FarEastLineBreakControl = True

.WordWrap = True

.HangingPunctuation = True

.HalfWidthPunctuationOnTopOfLine = False

.AddSpaceBetweenFarEastAndAlpha = True

.AddSpaceBetweenFarEastAndDigit = True

.BaseLineAlignment = wdBaselineAlignAuto

End With

' 清除原有的段落底纹

Selection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic

codeLineNumber = Selection.Paragraphs.Count

With Selection.Tables(1).Columns(1)

For i = 1 To codeLineNumber - 1

Selection.TypeText Text:=i

Selection.TypeParagraph

Next

Selection.TypeText Text:=行数

End With

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值