|
主要是用WPS使用,请各位大佬帮忙看看,运行最后插入文件时,文件名使用变量就报错,设置为固定就可以,不会代码
Sub 改格式()
Dim str As String, i As Integer, j As Integer
j = 0
str = Application.ActiveDocument.Paragraphs(1).Range.Text
For i = 1 To Len(str)
If Mid(str, i, 1) = " " Then
Else
Exit For
End If
j = j + 1
Next
str = Right(str, Len(str) - j)
Application.ActiveDocument.Paragraphs(1).Range.Text = str
Application.ActiveDocument.Paragraphs(1).Range.Select
Selection.Font.Name = "方正小标宋_GBK"
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Find.Wrap = wdFindContinue
Selection.Find.Wrap = wdFindContinue
With Selection.Find
.Text = "主要:"
.Forward = True
.Wrap = wdFindContinue
.MatchCase = False
.MatchByte = True
.MatchWildcards = False
.MatchWholeWord = False
.MatchFuzzy = False
.Replacement.Text = ""
End With
With Selection.Find
.Style = ""
.Highlight = wdUndefined
With .Replacement
.Style = ""
.Highlight = wdUndefined
End With
End With
Selection.Find.Execute Replace:=wdReplaceNone
With Selection.Font
.Bold = -1
.BoldBi = -1
End With
With Selection.Find
.Text = "次要:"
.Forward = True
.Wrap = wdFindContinue
.MatchCase = False
.MatchByte = True
.MatchWildcards = False
.MatchWholeWord = False
.MatchFuzzy = False
.Replacement.Text = ""
End With
With Selection.Find
.Style = ""
.Highlight = wdUndefined
With .Replacement
.Style = ""
.Highlight = wdUndefined
End With
End With
Selection.Find.Execute Replace:=wdReplaceNone
With Selection.Font
.Bold = -1
.BoldBi = -1
End With
Selection.EndKey Unit:=wdStory, Extend:=wdMove
Selection.Collapse Direction:=wdCollapseStart
With Selection
.InsertBreak Type:=wdSectionBreakNextPage
End With
Selection.InsertFile FileName:="C:\Users\Administrator\Desktop\WPS版自动按名称插入文件并设置文档文字格式" & str & "图片.docx"
End Sub
(主要通过录制宏获取的代码,如果可以精简代码也帮忙看看,正文标题设置字体格式,几个固定关键字处加粗。插入文件的位置可以是同一路径下。)
|
|