当前位置:首页经验技巧Word经验word文档

如何将word批量命名word文件名自动改成文档的首行的内容

2026-01-21 10:34:49

1.如何将word批量命名word文件名自动改成文档的首行的内容

Sub ChangeDocName(sPath As String)

Dim wdApp

Dim oDoc

Dim sFileName As String

Dim sNewName As String

Dim i As Integer

On Error Resume Next

Set wdApp = CreateObject("Word.Application")

On Error GoTo 0

If wdApp Is Nothing Then

MsgBox "创建word实例失败,程序将退出。本程序只能在装有word程序的电脑上运行。"

Exit Sub

End If

If Right(sPath, 1) "\" Then sPath = sPath & "\"

sFileName = Dir(sPath & "*.doc", vbHidden + vbSystem)

Do While sFileName ""

i = 0

Set oDoc = wdApp.Documents.Open(sapth & sFileName)

oDoc.Select

wdApp.Selection.HomeKey Unit:=wdStory

wdApp.Selection.Expand wdLine

sNewName = wdApp.Selection.Text

sNewName = Replace(sNewName, "\", "")

sNewName = Replace(sNewName, "/", "")

sNewName = Replace(sNewName, ":", "")

sNewName = Replace(sNewName, "?", "")

sNewName = Replace(sNewName, "*", "")

sNewName = Replace(sNewName, ">", "")

sNewName = Replace(sNewName, "sNewName = Replace(sNewName, """", "")

oDoc.Close

Err.Clear

On Error GoTo FileAlreadyExist

Name sPath & sFileName As sPath & sNewName & ".doc"

FileAlreadyExist:

If Err.Number >0 Then

i = i + 1

Name sPath & sFileName As sPath & sNewName & i & ".doc"

End If

On Error GoTo 0

sFileName = Dir()

Loop

Set wdApp = Nothing

End Sub

上述代码中已经加入了常见错误的处理,使用的时候将文件夹的完整路径作为参数输入就可以了。

2.在Word文档中怎么设置每一行的行号

方法/步骤

1

首先:打开需要显示行号的Word文档

2

然后:点击菜单“文件”-“页面设置”,然后切换到“版式”标签,点击“页面设置”窗口下部的“行号”按钮

3

然后:在“行号”窗口中设置行号的各参数,请参照下图,设置好后点击“确定”

4

至此,行号的显示设置就完成了

END

方法/步骤2-取消行号

首先:选中要取消行号的每一行

然后:点击菜单“格式”》“段落”,切换到“换行与分页”选项卡,勾选“取消行号”,点击“确定”

3

取消行号完成。


免责声明:本站信息来自网络收集及网友投稿,仅供参考,如果有错误请反馈给我们更正,对文中内容的真实性和完整性本站不提供任何保证,不承但任何责任,谢谢您的合作。
版权所有:五学知识网 Copyright © 2015-2026 www.z8000w.com. All Rights Reserved .