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: 07:54
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






TM-Town
Manage your TMs and Terms ... and boost your translation business

Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.

More info »
Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

Buy now! »