VBA: DOC to DOCX issue
Thread poster: DZiW (X)
DZiW (X)
DZiW (X)
Ukraine
English to Russian
+ ...
Apr 18, 2019

I found a useful script to convert all DOC files in a folder to DOCX:
Sub TranslateDocIntoDocx()
Dim objWordApplication As New Word.Application
Dim objWordDocument As Word.Document
Dim strFile As String
Dim strFolder As String

' No need for a menu atm
' With Application.FileDialog(4) ' msoFileDialogFolderPicker
' If .Show Then
' strFolder = .SelectedItems(1)
' Else
' MsgBox "No folder specified.", vbExclamation
' Exit Sub
' End If

strFolder = "f:\documents\"
strFile = Dir(strFolder & "*.doc", vbNormal)

While strFile ""
With objWordApplication
Set objWordDocument = .Documents.Open(FileName:=strFolder &strFile, AddToRecentFiles:=False, ReadOnly:=True, Visible:=False)

With objWordDocument
.SaveAs FileName:=strFolder & Replace(strFile, "doc", "docx"), FileFormat:=16
.Close
End With
End With
strFile = Dir()

application.statusbar = strFile

Wend

Set objWordDocument = Nothing
Set objWordApplication = Nothing
End Sub
which works fine, except locking the processed files by ghost Winword processes. So I have to shut them via Task Manager first.

Could you suggest what to change--or a better solution?

Also, is it possible to combine both DOC and RTF in the the same filesearch?


Thank you

[Edited at 2019-04-19 19:42 GMT]


 
Rolf Keller
Rolf Keller
Germany
Local time: 00:29
English to German
The macro isn't quite ok anyway Apr 19, 2019

I don't know if the following hint helps solving the issue, but the macro is faulty anyway and should be corrected:

The "Set objWordDocument = Nothing" should be placed inside the loop, between the .Close and the Wend. Otherwise any "Set objWordDocument =" creates an additional new object while the old object remains in memory as an unnamed & unaccessible zombie. That's the classic method for creating memory leaks, and nobody knows, what the zombies do resp whether they block their
... See more
I don't know if the following hint helps solving the issue, but the macro is faulty anyway and should be corrected:

The "Set objWordDocument = Nothing" should be placed inside the loop, between the .Close and the Wend. Otherwise any "Set objWordDocument =" creates an additional new object while the old object remains in memory as an unnamed & unaccessible zombie. That's the classic method for creating memory leaks, and nobody knows, what the zombies do resp whether they block their files.
https://excelmacromastery.com/vba-objects/#Creating_a_VBA_Object
Collapse


DZiW (X)
 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

VBA: DOC to DOCX issue






CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »
Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »