|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 以文章题目为名保存文档()
- Dim myPG As Paragraph
- Dim Title, FullName As String, isBegin As Boolean
- Title = "": isBegin = False
- For Each myPG In ActiveDocument.Paragraphs
- With myPG.Range
- If .Font.Size = 22 Then
- isBegin = True
- Title = Title & Trim(Left(.Text, Len(.Text) - 1))
- ElseIf isBegin Then
- Exit For
- End If
- End With
- Next myPG
- If Len(Title) = 0 Then
- MsgBox "未获取到标题"
- Else
- FullName = ActiveDocument.FullName
- FullName = Left(FullName, InStrRev(FullName, "")) & _
- Left(Replace(Title, "?*:""<>\/|", ""), 255) & ".doc"
- 'Debug.Print FullName
- ActiveDocument.SaveAs2 FileName:=FullName, FileFormat:=wdFormatDocument
- End If
-
- End Sub
复制代码 |
|