Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 08-25-2019, 12:57 AM
gmayor's Avatar
gmayor gmayor is offline How to Save a word as text file after applying font with UTF-8 Windows 10 How to Save a word as text file after applying font with UTF-8 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

I hesitate to recommend this as it may create as many problems as it resolves, but assuming the previous macro worked and I don't see why it would as text files don't support fonts, then the following will process all the documents that match the parameters in the selected folder. Password protected documents are ignored.
The original files are unaltered.

Code:
Sub ProcessFolder()
'Graham Mayor - https://www.gmayor.com - Last updated - 25 Aug 2019
Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Dim strName As String
Dim oColl As Collection
Dim iCol As Integer
Const strPassword As String = "?#nonsense@$" 'do not change
Const strExt As String = "doc"    'the extension of the files to process - here word 97-2003 DOC format.
Const strFont As String = "Times New Roman"    'the font to apply (text files do not support fonts?)

    Set oColl = New Collection
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    With fDialog
        .TITLE = "Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Cancelled By User", , "List Folder Contents"
            Exit Sub
        End If
        strPath = fDialog.SelectedItems.Item(1)
        Do Until Right(strPath, 1) = Chr(92)
            strPath = strPath & Chr(92)
        Loop
    End With
    strFile = Dir$(strPath & "*.*")
    While strFile <> ""
        If LCase(Right(strFile, Len(strFile) - InStrRev(strFile, "."))) = strExt Then
            oColl.Add strPath & strFile
        End If
        DoEvents
        strFile = Dir$()
    Wend
    For iCol = 1 To oColl.Count
        On Error Resume Next
        WordBasic.DisableAutoMacros 1
        Set oDoc = Documents.Open(FileName:=oColl(iCol), _
                                  AddToRecentFiles:=False, _
                                  Visible:=True, _
                                  PasswordDocument:=strPassword, _
                                  ReadOnly:=True, _
                                  WritePasswordDocument:=strPassword)
        If oDoc Is Nothing Or Err.Number > 0 Then
            Err.Clear
            GoTo NextDoc:
        End If
        strName = Left(oDoc.FullName, InStrRev(oDoc.FullName, ".") - 1) & ".txt"
        oDoc.Range.Font.Name = strFont
        oDoc.SaveAs2 FileName:=strName, FileFormat:=wdFormatUnicodeText
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
        WordBasic.DisableAutoMacros 0
NextDoc:
        DoEvents
    Next iCol
    MsgBox "Processing complete"
lbl_Exit:
    Set oDoc = Nothing
    Set fDialog = Nothing
    Set oColl = Nothing
    Exit Sub
End Sub
__________________
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
 

Tags
save

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Save a word as text file after applying font with UTF-8 Word does not detect any text when applying style reference Stingerhawk Word 3 04-26-2019 01:33 AM
Save Document as Text File gerison Word VBA 5 11-27-2017 07:15 AM
Having Issues Applying a Macro Across Multiple Files. Changes Just Don't Seem To Save. Kajex Word VBA 2 09-08-2017 06:37 AM
Applying layout to existing slides without affecting font mgw130 PowerPoint 3 12-15-2012 04:38 AM
How to Save a word as text file after applying font with UTF-8 Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft