word selection style selectionstyle - 电脑|办公 - 电脑办公-杀毒安全-网络-V3学习网
微商网
 
 
导航:首页 |电脑|办公|正文

word selection style selectionstyle

时间:2020-07-20 08:17:07
在word中使用VBA区分标题和正文获取标题与正文使用style。试验一下如下代码。Sub Test()Dim i As SingleFor i = 1 To ActiveDocument Built
作者:

word selection style

在word中使用VBA区分标题和正文

获取标题与正文使用style。

试验一下如下代码。

Sub Test()Dim i As SingleFor i = 1 To ActiveDocument.BuiltInDocumentProperties(wdPropertyLines).ValueWith Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=i.HomeKey Unit:=wdLine.EndKey Unit:=wdLine, Extend:=wdExtendEnd WithIf Selection.Style = "正文" ThenMsgBox i & "行是正文"End IfIf Selection.Style = "标题 1" ThenMsgBox i & "行是标题 1"End IfNextEnd Sub

word2007在一个文件里将其“正文文本”替换为“无间隔”样式、字...

在进行大型项目的方案文档设计时,一个文档中有可能涉及到上百个图表,在最后定稿的时候,需要进行统一的格式化处理。

面对这些数目庞大的表格,挨个用格式刷进行处理,一路刷下来往往手都会刷酸,更令人奔溃的是好不容易刷完了,发现字体或大小不对,这时候可能需要再重新刷一遍。

那么如果能提高效率呢?word中的VBA功能,就是专为这种工作量庞大,而需要重复的工作设计的。

对表格的样式进行统一处理VBA代码如下:Sub FormatAllTables()For i = 1 To ActiveDocument.Tables.Count " ActiveDocument.Tables(i).Style = "my"With ActiveDocument.Tables(i).Range.ParagraphFormat.LeftIndent = CentimetersToPoints(0).RightIndent = CentimetersToPoints(0).SpaceBefore = 0.SpaceBeforeAuto = False.SpaceAfter = 0.SpaceAfterAuto = False.LineSpacingRule = wdLineSpace1pt5.Alignment = wdAlignParagraphJustify.WidowControl = False.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" 设置表中的字体及大小ActiveDocument.Tables(i).SelectWith Selection.Font.Size = 12.Font.Name = "宋体"End WithActiveDocument.Tables(i).Cell(1, 1).SelectWith Selection.SelectRow.Font.Bold = True.Shading.BackgroundPatternColor = -603923969.ParagraphFormat.Alignment = wdAlignParagraphCenter End WithNextEnd Sub123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354在文档编写中,表格中题注的字体及大小一般与正文也不一样,需要单独进行设置,由于题注设置需要自动编号,可通过VBA代码对这些自动编号的题注进行自动化处理,其基本思路是查找带有域“图”的所有文本;选中它,然后格式粘贴。

其代码如下:Sub FormatTableTitle()myHeadings = ActiveDocument.GetCrossReferenceItems("图")findTxt = ""For i = 1 To UBound(myHeadings) "MsgBox myHeadings(i)findTxt = myHeadings(i) With Selection.Find.Text = findTxt.Replacement.Text = "".Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithSelection.Find.ExecuteSelection.PasteFormat Next iEnd Sub

VBA的注意

//b。

Word 在 VBA 编程语言中把宏录制为一系列的 Word 命令,Font 是返回一个 Font 对象的 Selection 对象的一个属性.Bold要在 Visual Basic 中执行一个任务。

这意味着可以将 Bold 属性设置为 True 或 False(真或假),也可返回当前值。

下面 WordBasic 指令的返回值表明是否将加粗格式应用于所选内容。

x = Bold()下面的示例是 Visual Basic 语句。

Selection:宏录制器和 Visual Basic 编辑器。

宏录制器可帮助用户开始创建宏。

也可用 Visual Basic 编辑器创建包括 Visual Basic 指令的非常灵活和强有力的宏,Selection,以找到包含需要修改的 Font 对象的对象,可以通过不同的对象(如 Style、Selection 和 Find 对象)来访问 Font 对象,它是一个自定义命令,Word 2000 将自动转换 Word 6.x 或 Word 95 模板中的宏。

群群我爱你7哮 | 发布于2016-05-09 评论

如何用C#实现Word里的字体选择下拉列表框

给Combox添加Item的时候在初始化时执行一次就OK了,如果放在DropDown事件里就会DropDown一次执行一次, 改成下面方式没有发现你所描述的问题。

public Form1(){InitializeComponent();System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();foreach (string name in FontSizeName){this.toolStripComboBox2.Items.Add(name);}}public string[] FontSizeName = { "8", "9", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72", "初号", "小初", "一号", "小一", "二号", "小二", "三号", "小三", "四号", "小四", "五号", "小五", "六号", "小六", "七号", "八号" };public float[] FontSize = { 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 42, 36, 26, 24, 22, 18, 16, 15, 14, 12, 10.5F, 9, 7.5F, 6.5F, 5.5F, 5 };//定义字号数组private void toolStripComboBox1_DropDown(object sender, EventArgs e){}private void toolStripComboBox2_DropDown(object sender, EventArgs e){/*System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();foreach (string name in FontSizeName){this.toolStripComboBox2.Items.Add(name);}*/}private void toolStripComboBox2_SelectedIndexChanged(object sender, EventArgs e){this.richTextBox1.SelectionFont = new Font(this.toolStripComboBox1.Text, FontSize[this.toolStripComboBox2.SelectedIndex], this.richTextBox1.SelectionFont.Style);}

一级标题缩进设置为0字符不起作用?office

Sub 前123级标题() "测试结果 1 代码重复运行1次才能调整好。

Selection.HomeKey wdStory "光标移到最前面。

Dim p As Paragraph For Each p In ActiveDocument.Paragraphs If p.Style = "标题 1" Then p.LeftIndent = 0 "段落的绝对左缩进量(以磅为单位) If p.Style = "标题 1" Then p.RightIndent = 0 "段落的绝对左缩进量(以磅为单位) If p.Style = "标题 1" Then p.FirstLineIndent = CentimetersToPoints(0) "首行缩进0cm(只对单位是cm的缩进有效) If p.Style = "标题 1" Then p.CharacterUnitFirstLineIndent = 0 "首行缩进0磅(只对单位是磅的缩进有效) If p.Style = "标题 2" Then p.LeftIndent = 0 "段落的绝对左缩进量(以磅为单位) If p.Style = "标题 2" Then p.RightIndent = 0 "段落的绝对左缩进量(以磅为单位) If p.Style = "标题 2" Then p.FirstLineIndent = CentimetersToPoints(0) "首行缩进0cm(只对单位是cm的缩进有效) If p.Style = "标题 2" Then p.CharacterUnitFirstLineIndent = 0 "首行缩进0磅(只对单位是磅的缩进有效) If p.Style = "标题 3" Then p.LeftIndent = 0 "段落的绝对左缩进量(以磅为单位) If p.Style = "标题 3" Then p.RightIndent = 0 "段落的绝对左缩进量(以磅为单位) If p.Style = "标题 3" Then p.FirstLineIndent = CentimetersToPoints(0) " "首行缩进0cm If p.Style = "标题 3" Then p.CharacterUnitFirstLineIndent = 0 "首行缩进0磅(只对单位是磅的缩进有效) If p.Style = "标题 1" Then p.FirstLineIndent = CentimetersToPoints(0) "首行缩进0cm(只对单位是cm的缩进有效) If p.Style = "标题 1" Then p.CharacterUnitFirstLineIndent = 0 "首行缩进0磅(只对单位是磅的缩进有效) If p.Style = "标题 2" Then p.FirstLineIndent = CentimetersToPoints(0) "首行缩进0cm(只对单位是cm的缩进有效) If p.Style = "标题 2" Then p.CharacterUnitFirstLineIndent = 0 "首行缩进0磅(只对单位是磅的缩进有效) If p.Style = "标题 3" Then p.FirstLineIndent = CentimetersToPoints(0) " "首行缩进0cm If p.Style = "标题 3" Then p.CharacterUnitFirstLineIndent = 0 "首行缩进0磅(只对单位是磅的缩进有效) Next Selection.Move " If p.Style = "标题 1" Then p.Range.Font.Color = vbBlack "blue " If p.Style = "标题 1" Then p.Format.LineSpacingRule = wdLineSpaceExactly "行距固定值 " If p.Style = "标题 1" Then p.Format.LineSpacing = 20 "行距固定值= 20 " If p.Style = "标题 1" Then p.Format.SpaceBefore = 0 "段前距为0 " If p.Style = "标题 1" Then p.Format.SpaceAfter = 0 "段后距为0 " If p.Style = "标题 1" Then p.LeftIndent = 0 "段落的绝对左缩进量(以磅为单位) " If p.Style = "标题 1" Then p.RightIndent = 0 "段落的绝对右缩进量(以磅为单位) " If p.Style = "标题 1" Then p.Range.Bold = True "加粗 " If p.Style = "标题 1" Then p.CharacterUnitFirstLineIndent = InchesToPoints(0) "度量单位从英寸转换为磅Points Selection.HomeKey wdStory "光标移到最前面。

" D图片居中 End Sub

c#怎么做像word那样的文字大小下拉选择栏?要求有word那样的效果

//添加一个comboBox,一个richTextBoxprivate void Form1_Load(object sender, EventArgs e){int[] arrFont = { 10, 20, 32, 34, 36, 40 };for (int i = 0; i < arrFont.Length; i++) {comboBox1.Items.Add(arrFont[i]);}}private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){Font font = new Font(FontFamily.GenericSerif,int.Parse(comboBox1.Text), FontStyle.Regular);richTextBox1.SelectionFont = font;}

VB 如何控制WORD中插入图片的大小等属性?

自己录个宏,稍加改动就可以了。

Sub 图片旋转270度对齐页面()"图片排版270度 If Selection.InlineShapes.Count = 0 Then If Selection.ShapeRange.Count 0 Then Selection.ShapeRange.Fill.Visible = msoFalse "Selection.ShapeRange.AlternativeText = "Higer标书工具修改" Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoFalse Selection.ShapeRange.LockAspectRatio = msoFalse Selection.ShapeRange.Rotation = 270# Selection.ShapeRange.Width = CentimetersToPoints(28.9) Selection.ShapeRange.Height = CentimetersToPoints(20.2) "Selection.ShapeRange.PictureFormat.Brightness = 0.5 "Selection.ShapeRange.PictureFormat.Contrast = 0.5 "Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic Selection.ShapeRange.PictureFormat.CropLeft = 0# Selection.ShapeRange.PictureFormat.CropRight = 0# Selection.ShapeRange.PictureFormat.CropTop = 0# Selection.ShapeRange.PictureFormat.CropBottom = 0# "Selection.ShapeRange.Left = 90.1 "Selection.ShapeRange.Top = 88.15 "Selection.ShapeRange.Left = -120.45 "Selection.ShapeRange.Top = 109.1 Selection.ShapeRange.RelativeHorizontalPosition = _ wdRelativeHorizontalPositionPage Selection.ShapeRange.RelativeVerticalPosition = _ wdRelativeVerticalPositionPage Selection.ShapeRange.Left = wdShapeCenter Selection.ShapeRange.Top = wdShapeCenter Selection.ShapeRange.LockAnchor = False Selection.ShapeRange.LayoutInCell = True Selection.ShapeRange.WrapFormat.AllowOverlap = True Selection.ShapeRange.WrapFormat.Side = wdWrapBoth Selection.ShapeRange.WrapFormat.DistanceTop = CentimetersToPoints(0) Selection.ShapeRange.WrapFormat.DistanceBottom = CentimetersToPoints(0) Selection.ShapeRange.WrapFormat.DistanceLeft = CentimetersToPoints(0.32) Selection.ShapeRange.WrapFormat.DistanceRight = CentimetersToPoints(0.32) Selection.ShapeRange.WrapFormat.Type = 3 Selection.ShapeRange.ZOrder 4 Selection.ShapeRange.ZOrder msoSendBackward End If End If If Selection "" Then If Selection.InlineShapes.Count 0 Then "Selection.InlineShapes(1).Fill.Visible = msoFalse "Selection.InlineShapes(1).Fill.Solid "Selection.InlineShapes(1).Fill.Transparency = 0# "Selection.InlineShapes(1).Line.Weight = 0.75 "Selection.InlineShapes(1).Line.Transparency = 0# "Selection.InlineShapes(1).Line.Visible = msoFalse "Selection.InlineShapes(1).LockAspectRatio = msoFalse "Selection.InlineShapes(1).Width = CentimetersToPoints(28.9) "Selection.InlineShapes(1).Height = CentimetersToPoints(20.2) "Selection.InlineShapes(1).PictureFormat.Brightness = 0.5 "Selection.InlineShapes(1).PictureFormat.Contrast = 0.5 "Selection.InlineShapes(1).PictureFormat.ColorType = msoPictureAutomatic "Selection.InlineShapes(1).PictureFormat.CropLeft = 0# "Selection.InlineShapes(1).PictureFormat.CropRight = 0# "Selection.InlineShapes(1).PictureFormat.CropTop = 0# "Selection.InlineShapes(1).PictureFormat.CropBottom = 0# Selection.InlineShapes(1).ConvertToShape "属性转换(InlineShapes(1)转换为ShapeRange) Selection.ShapeRange.Fill.Visible = msoFalse "Selection.ShapeRange.AlternativeText = "Higer标书工具修改" Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoFalse Selection.ShapeRange.LockAspectRatio = msoFalse Selection.ShapeRange.Width = CentimetersToPoints(28.9) Selection.ShapeRange.Height = CentimetersToPoints(20.2) Selection.ShapeRange.Rotation = 270# "Selection.ShapeRange.PictureFormat.Brightness = 0.5 "Selection.ShapeRange.PictureFormat.Contrast = 0.5 "Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic Selection.ShapeRange.PictureFormat.CropLeft = 0# Selection.ShapeRange.PictureFormat.CropRight = 0# Selection.ShapeRange.PictureFormat.CropTop = 0# Selection.ShapeRange.PictureFormat.CropBottom = 0# Selection.ShapeRange.RelativeHorizontalPosition = _ wdRelativeHorizo...

大家还关注
    
阅读排行
推荐阅读