none
.txt files do not appear in the Documents collection RRS feed

  • Question

  • Hi everyone,

    When I open a file created with Notepad in Word and subsequently check the Documents collection, the file is not included. The same goes for the Windows collection. I'm writing a VBA macro that must manipulate .txt files in a certain way; it'd be nice if Word recognized that the intended file is open.

    How can I get Word to recognize a .txt file as an open document, so that I can get to its Paragraphs collection?

    I'm using Word 2016.

    Thanks!
    Cooz 


    • Edited by Cooz2 Thursday, December 28, 2017 2:45 PM
    Thursday, December 28, 2017 2:44 PM

All replies

  • There is no reason why Word 2016 cannot list the open documents - even if that includes text files. What does the following produce in the immediate window when you have a text file open in Word.

    Sub Test()
    Dim oDoc As Document
        For Each oDoc In Documents
    Debug.Print oDoc.FullName
            If Right(oDoc.Name, 3) = "txt" Then
    Debug.Print oDoc.Paragraphs.Count
            End If
        Next oDoc
    End Sub
    


    Graham Mayor - Word MVP
    www.gmayor.com

    Friday, December 29, 2017 4:49 AM
  • Hi Graham,

    "There is no reason why Word 2016 cannot list the open documents - even if that includes text files."

    Indeed there isn't, and all of a sudden it works fine! I don't know what happened.

    Thanks for your contribution.

    Cooz

    Friday, December 29, 2017 9:07 AM