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: 13:03
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






Anycount & Translation Office 3000
Translation Office 3000

Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.

More info »
Protemos translation business management system
Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!

The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.

More info »