石家庄铁道大学毕业论文格式设置
使用方法
在word中找到开发工具->VB,点击写代码
注:若没有,点击文件->更多->选项
勾选开发工具,即可在标签栏看到
代码工具
设置正文中字母与数字的格式为Times New Roman
Sub SetEnglishAndNumbersFontToTimesNewRoman()
Dim rng As Range
Dim doc As Document
Dim para As Paragraph
Dim i As Integer
' 获取当前活动文档
Set doc = ActiveDocument
' 循环遍历文档中的每个段落
For Each para In doc.Paragraphs
' 设置段落范围
Set rng = para.Range
' 检查段落中的文本是否为英文或数字
For i = 1 To Len(rng.Text)
If IsNumeric(Mid(rng.Text, i, 1)) Or (Asc(Mid(rng.Text, i, 1)) >= 65 And Asc(Mid(rng.Text, i, 1)) <= 122) Then
' 设置文本的字体为Times New Roman
rng.Font.Name = "Times New Roman"
End If
Next i
Next para
End Sub
设置参考文献到文字角标
Sub MoveReferencesToSuperscript()
Dim rng As Range
Dim doc As Document
Dim para As Paragraph
Dim startPos As Long
Dim endPos As Long
' 获取当前活动文档
Set doc = ActiveDocument
' 循环遍历文档中的每个段落
For Each para In doc.Paragraphs
' 设置段落范围
Set rng = para.Range
' 检查段落中的文本是否包含参考文献样式,例如"[1]", "[2]", "[3]"等
startPos = InStr(rng.Text, "[")
endPos = InStr(rng.Text, "]")
If startPos > 0 And endPos > startPos Then
' 设置文本的格式为上标
rng.SetRange Start:=rng.Start + startPos - 1, End:=rng.Start + endPos
rng.Font.Superscript = True
End If
Next para
End Sub
将所有表格设置为三线表
Sub SetTableFormatWithThreeLines()
Dim tbl As Table
Dim cell As cell
Dim row As row
Dim doc As Document
' 获取当前活动文档
Set doc = ActiveDocument
' 遍历文档中的每个表格
For Each tbl In doc.Tables
' 删除表格中的所有边框
tbl.Borders.Enable = False
' 遍历每个单元格并设置字体和段落格式
For Each row In tbl.Rows
For Each cell In row.Cells
With cell.Range
.Font.Size = 10
.Font.Name = "宋体"
.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
End With
Next cell
Next row
' 设置三条边框
With tbl.Borders
' 设置顶部和底部边框为粗线
.InsideLineStyle = wdLineStyleNone
.OutsideLineStyle = wdLineStyleNone
' 设置顶部边框为粗线
.Item(wdBorderTop).LineStyle = wdLineStyleSingle
.Item(wdBorderTop).LineWidth = wdLineWidth100pt
' 设置底部边框为粗线
.Item(wdBorderBottom).LineStyle = wdLineStyleSingle
.Item(wdBorderBottom).LineWidth = wdLineWidth100pt
End With
' 设置第二行单元格的顶部边框为细线
With tbl.Rows(2)
.Cells.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Cells.Borders(wdBorderTop).LineWidth = wdLineWidth050pt
End With
Next tbl
End Sub
设置正文文本与标题格式
Sub SetDocumentFormat()
Dim doc As Document
' 获取当前活动文档
Set doc = ActiveDocument
' 设置正文部分格式
With doc.Styles(wdStyleNormal).Font
.Size = 12 ' 小四号字体
.Name = "宋体"
End With
doc.Paragraphs.Format.Alignment = wdAlignParagraphJustify ' 两端对齐
doc.Paragraphs.Format.LineSpacingRule = wdLineSpaceExactly
doc.Paragraphs.Format.LineSpacing = 20 ' 20磅行距
doc.Paragraphs.Format.FirstLineIndent = Application.CentimetersToPoints(0.42) ' 首行缩进2字符
' 设置一级标题格式
With doc.Styles(wdStyleHeading1).Font
.Size = 14 ' 小三号字体
.Name = "黑体"
End With
doc.Styles(wdStyleHeading1).ParagraphFormat.Alignment = wdAlignParagraphCenter ' 居中对齐
doc.Styles(wdStyleHeading1).ParagraphFormat.SpaceBefore = 30 ' 段前30磅
doc.Styles(wdStyleHeading1).ParagraphFormat.SpaceAfter = 30 ' 段后30磅
' 设置二级标题格式
With doc.Styles(wdStyleHeading2).Font
.Size = 12 ' 四号字体
.Name = "黑体"
End With
doc.Styles(wdStyleHeading2).ParagraphFormat.Alignment = wdAlignParagraphLeft ' 左对齐
doc.Styles(wdStyleHeading2).ParagraphFormat.SpaceBefore = 18 ' 段前18磅
doc.Styles(wdStyleHeading2).ParagraphFormat.SpaceAfter = 12 ' 段后12磅
' 设置三级标题格式
With doc.Styles(wdStyleHeading3).Font
.Size = 13 ' 13磅字体
.Name = "黑体"
End With
doc.Styles(wdStyleHeading3).ParagraphFormat.Alignment = wdAlignParagraphLeft ' 左对齐
doc.Styles(wdStyleHeading3).ParagraphFormat.SpaceBefore = 12 ' 段前12磅
doc.Styles(wdStyleHeading3).ParagraphFormat.SpaceAfter = 12 ' 段后12磅
' 设置四级标题格式
With doc.Styles(wdStyleHeading4).Font
.Size = 12 ' 小四号字体
.Name = "黑体"
End With
doc.Styles(wdStyleHeading4).ParagraphFormat.Alignment = wdAlignParagraphLeft ' 左对齐
doc.Styles(wdStyleHeading4).ParagraphFormat.SpaceBefore = 6 ' 段前6磅
doc.Styles(wdStyleHeading4).ParagraphFormat.SpaceAfter = 6 ' 段后6磅
End Sub