vb-office-doc-to-docx
 2021-06-28 17:06:05   138   0   

本文最后更新于天前,文中介绍内容及环境可能已不适用.请谨慎参考.

单层级 doc-docx

Sub ConvertBatchToDOCX()
    Dim sSourcePath As String
    Dim sTargetPath As String
    Dim sDocName As String
    Dim docCurDoc As Document
    Dim sNewDocName As String

    ' Looking in this path
    sSourcePath = "F:\wz\003-报告\后评价\2016问题建议后评价2-xls2\"
  

   ' Look for first DOC file
    sDocName = Dir(sSourcePath & "*.doc")
    Do While sDocName <> ""
    
     
        ' Repeat as long as there are source files
        
        'Only work on files where right-most characters are ".doc"
        If Right(sDocName, 4) = ".doc" Then
        
          
            
            ' Open file
              Set docCurDoc = Documents.Open(FileName:=sSourcePath & sDocName)


            sNewDocName = Replace(sDocName, ".doc", ".docx")

            With docCurDoc
                .SaveAs FileName:=sTargetPath & sNewDocName, _
                  FileFormat:=wdFormatDocumentDefault
                .Close SaveChanges:=wdDoNotSaveChanges
                
                
            End With
            
         
        End If
        ' Get next source file name
        sDocName = Dir
        
        
        
    Loop
    MsgBox "Finished"
End Sub

 

 

使用office宏命令 2级目录转换doc- docx

 

Sub ConvertBatchToDOCX()
    Dim sSourcePath As String
   
    Dim sDocName As String
    Dim sDocNameOut As String
    Dim docCurDoc As Document
    Dim sNewDocName As String

    ' Looking in this path
    sSourcePath = "F:\wz\003-报告\后评价\2015问题建议后评价1-xls2\"
  
    Dim p2 As String

   ' Look for first DOC file
   
    Set fso = CreateObject("scripting.filesystemobject") '创建FSO对象
    Set folder = fso.getfolder(sSourcePath)
   
   
    For Each sfd In folder.SubFolders
        ' MsgBox (sfd)
       ' FindFile sfd, FileName  ' 循环查找
       
         p2 = sfd.Path + "\"
         
         sDocName = Dir(p2 & "*.doc")
         Do While sDocName <> ""
        
         
            
        ' Repeat as long as there are source files
        
        'Only work on files where right-most characters are ".doc"
            If Right(sDocName, 4) = ".doc" And Left(sDocName, 5) = "4-最终版" Then
        
          
            
            ' Open file
                Set docCurDoc = Documents.Open(FileName:=p2 & sDocName)


                sNewDocName = Replace(sDocName, ".doc", ".docx")

                With docCurDoc
                    .SaveAs FileName:=p2 & sNewDocName, _
                    FileFormat:=wdFormatDocumentDefault
                    .Close SaveChanges:=wdDoNotSaveChanges
                
                
                End With
            
         
             End If
        ' Get next source file name
            
             sDocName = Dir
             
        Loop
    Next
    
   
  
    MsgBox "Finished"
End Sub



 


 2021-06-28 17:06:05 
 0

  本文基于CC BY-NC-ND 4.0 许可协议发布,作者:野生的喵喵 固定链接: 【vb-office-doc-to-docx】 转载请注明



发表新的评论
{{s_uid}}   , 欢迎回来.
您的称呼(*必填):
您的邮箱地址(*必填,您的邮箱地址不会公开,仅作为有回复后的消息通知手段):
您的站点地址(选填):
留言:

∑( ° △ °|||)︴

(๑•̀ㅂ•́)و✧
<( ̄) ̄)>
[]~( ̄▽ ̄)~*
( ̄ˇ ̄)
[]~( ̄▽ ̄)~*
( ̄ˇ ̄)
╮( ̄▽ ̄)╭
( ̄ε(# ̄)
(⊙ˍ⊙)
( ̄▽ ̄)~*
∑( ° △ °|||)︴

文章分类

可能喜欢 

KxのBook@Copyright 2017- All Rights Reserved
Designed and themed by 野生的喵喵   1621837   44919