View Single Post
 
Old 08-26-2019, 03:56 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,104
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

That won't work. If you save as TXT, oDoc is then the text file that you have just saved.

To save the file as docx, you would either have to forget saving as txt and save as docx, or simply save oDoc instead of saving it as txt. e.g.

Code:
        'strName = Left(oDoc.FullName, InStrRev(oDoc.FullName, ".") - 1) & ".txt"
        'oDoc.Range.Font.Name = strFont
	oDoc.Save
        'oDoc.SaveAs2 FileName:=strName, FileFormat:=wdFormatUnicodeText
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
If you want it as txt as well as docx then

Code:
        strName = Left(oDoc.FullName, InStrRev(oDoc.FullName, ".") - 1) & ".txt"
        oDoc.Range.Font.Name = strFont
	oDoc.Save
        oDoc.SaveAs2 FileName:=strName, FileFormat:=wdFormatUnicodeText
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
Or SaveAs again e.g.

Code:
        strName = Left(oDoc.FullName, InStrRev(oDoc.FullName, ".") - 1) & ".txt"
        oDoc.Range.Font.Name = strFont
        oDoc.SaveAs2 FileName:=strName, FileFormat:=wdFormatUnicodeText
	strName = Left(oDoc.FullName, InStrRev(oDoc.FullName, ".") - 1) & ".docx"
	oDoc.SaveAs2 FileName:=strName, FileFormat:=wdFormatXMLDocument
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote