VBA: DOC to DOCX issue
Thread poster: DZiW

DZiW
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
Germany
Local time: 16:48
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
 


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

Advanced search






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 SDL Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

More info »
PerfectIt consistency checker
Faster Checking, Greater Accuracy

PerfectIt helps deliver error-free documents. It improves consistency, ensures quality and helps to enforce style guides. It’s a powerful tool for pro users, and comes with the assurance of a 30-day money back guarantee.

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search