Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2021, 06:21 AM
kalagas kalagas is offline Batch convert doc to docx Windows 10 Batch convert doc to docx Office 2019
Novice
Batch convert doc to docx
 
Join Date: Nov 2019
Posts: 9
kalagas is on a distinguished road
Default Batch convert doc to docx

Hi to all.
I have over 2000 word files inside a folder and subfolders and i would like to change them from old DOC to DOCX.

So I want to change all DOC files inside a folder AND it's subfolders to DOCX.
If it's possible i would like also to have the option to delete the original DOC files after the conversion.

Thanks in advanced for your time and help.
Reply With Quote
  #2  
Old 02-27-2021, 07:28 AM
gmaxey gmaxey is offline Batch convert doc to docx Windows 10 Batch convert doc to docx Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,204
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

See:
Process Batch Folder Add-In
Reply With Quote
  #3  
Old 02-28-2021, 06:00 AM
macropod's Avatar
macropod macropod is offline Batch convert doc to docx Windows 10 Batch convert doc to docx Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,224
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Simply saving in the docx format will wipe out any VBA code the existing documents might contain (including for ActiveX controls). Try:

Code:
Option Explicit
Dim FSO As Object, oFolder As Object, StrFolds As String
 
Sub Main()
Application.ScreenUpdating = False
Dim TopLevelFolder As String, TheFolders As Variant, aFolder As Variant, i As Long
TopLevelFolder = GetFolder
StrFolds = vbCr & TopLevelFolder
If FSO Is Nothing Then
  Set FSO = CreateObject("Scripting.FileSystemObject")
End If
'Get the sub-folder structure
Set TheFolders = FSO.GetFolder(TopLevelFolder).SubFolders
For Each aFolder In TheFolders
  RecurseWriteFolderName (aFolder)
Next
'Process the documents in each folder
For i = 1 To UBound(Split(StrFolds, vbCr))
  Call UpdateDocuments(CStr(Split(StrFolds, vbCr)(i)))
Next
Application.ScreenUpdating = True
End Sub

Sub RecurseWriteFolderName(aFolder)
Dim SubFolders As Variant, SubFolder As Variant
Set SubFolders = FSO.GetFolder(aFolder).SubFolders
StrFolds = StrFolds & vbCr & CStr(aFolder)
On Error Resume Next
For Each SubFolder In SubFolders
  RecurseWriteFolderName (SubFolder)
Next
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Sub UpdateDocuments(oFolder As String)
Dim strFldr As String, strFile As String, wdDoc As Document
strFldr = oFolder: If strFldr = "" Then Exit Sub
strFile = Dir(strFldr & "\*.doc", vbNormal)
While strFile <> ""
  If Not Split(strFile, ".doc")(1) Like "[xm]" Then
    Set wdDoc = Documents.Open(FileName:=strFldr & "\" & strFile, AddToRecentFiles:=False, ReadOnly:=False, Visible:=False)
    With wdDoc
      'Save as docx or docm, depending on whether the file contains macros.
      If .HasVBProject = False Then
        .SaveAs2 FileName:=.FullName & "x", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
      Else
        .SaveAs2 FileName:=.FullName & "m", FileFormat:=wdFormatXMLDocumentMacroEnabled, AddToRecentFiles:=False
      End If
      'close the document
      .Close False
    End With
    'Delete the old file
    Kill strFldr & "\" & strFile
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch convert doc to docx Batch applying a macro to remove Header and Footer using Batch Auto Addin Edszx Word VBA 2 05-27-2019 11:16 PM
Batch convert doc to docx Batch instruction works or ".doc" in folder, but not ".docx" raymondroe Word VBA 4 02-15-2015 01:19 AM
Remove Compatibility Mode on DOCX files (batch) w64bit Word 17 02-01-2015 06:02 AM
Batch convert doc to docx Batch convert multiple 32 bit xslx to 32 bit docx mapl Excel 2 06-14-2013 05:29 PM
Convert error docx--> doc: You cannot put drawings into a text box, callout, comment, pstein Word 5 07-29-2012 09:06 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft