加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

excel word vba 批量重命名  去除文件名里的括号

(2011-06-08 18:03:00)
标签:

杂谈

分类: Excel Vba

 

在word里面的vba运行,excel里的vba运行可能会出错

 

 

Sub kqbt_DelPar()
  On Error Resume Next
  Application.ScreenUpdating = False
  Dim MyPath As String, newPath As String, i As Integer, myDoc As Document
  Dim myTitle$, myFileName$
  Dim filename As String, OldName As String, NewName As String
 
  With Application.FileDialog(msoFileDialogFolderPicker) '选择存放word文档的文件夹,并将路径存放于myPath变量
    .Title = "选择源文件夹"
    If .Show = -1 Then
      MyPath = .SelectedItems(1)
    Else
      Exit Sub
    End If
  End With

 

With Application.FileSearch
    .LookIn = MyPath
    .FileType = msoFileTypeWordDocuments
    If .Execute > 0 Then
      For i = 1 To .FoundFiles.Count
       filename = .FoundFiles(i)
       MsgBox (filename)
       OldName = filename
    filename = Replace(filename, "(", "")
    filename = Replace(filename, ")", "")
       NewName = filename
    Name OldName As NewName
    Next i
   End If
   End With
    

End Sub

 

 

参考

Sub 文件改名()
Dim OldName As String, NewName As String
OldName = ThisWorkbook.Path & "\原文件名.txt"
NewName = ThisWorkbook.Path & "\新文件名.txt"
Name OldName As NewName
End Sub

http://club.excelhome.net/viewthread.php?tid=435043

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有