|
楼主 |
发表于 2019-9-9 17:18
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 自动命名()
Dim t1$, t2$
Dim x As Integer
With ActiveDocument
If .Bookmarks.Exists("文号") And .Bookmarks.Exists("标题") Then
t1 = .Bookmarks("文号").Range.Text
t2 = .Bookmarks("标题").Range.Text
fs = GetName(t1 & ":" & t2)
x = MsgBox("是否将文件另存为:" & fs & "?", 4)
If x = 7 Then Exit Sub
.SaveAs .Path & "\" & fs & ".docx"
End If
End With
End Sub
Function GetName(ByVal aStr As String) As String
Dim ErrArray() As Variant, oArray As Variant
ErrArray = Array("", "/", "*", ":", "?", "<", ">", "|", """", Chr$(7), Chr$(8), Chr$(9), Chr$(10), Chr$(11), Chr$(13))
For Each oArray In ErrArray
aStr = Replace(aStr, oArray, "")
Next
GetName = LTrim(aStr)
End Function
|
|