Results 1 to 4 of 4
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Insert File with unformatted text (Word 2002 SP-2)

    When I add plain ASCII text to a Word document using Paste Special and the Unformatted Text option, it seems to come in almost perfectly -- by which I mean that the result seems to be almost exactly the same as if, instead of performing the paste, I'd started at that same Insertion Point and manually typed the same text into that Word document. I say "almost" because the only difference I've found is that the "following style" of the IP paragraph is not respected; instead, all of the pasted paragraphs will have the same style as the IP paragraph.

    By contrast, if I take a plain ASCII text file and try to insert it into a Word document using Insert File, Word seems to insist on messing with it no matter what option I choose in the unavoidable "Convert File" dialog. Word applies the Plain Text style to the inserted text, and the characters between paragraphs are vbCrLf instead of vbCr. I can obviously run a clean-up macro to take care of those 2 issues, but I suspect there may be other unwanted messing around that I don't know about (those pesky vrCrLf's don't exactly stand up tall and announce their presence), and in any case I'd rather have a clean insert to begin with. Is there a way to use InsertFile and have the result be the same as a Paste Special with Unformatted Text?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Insert File with unformatted text (Word 2002 SP-2)

    I don't think there is a way of preventing Word from acting this way. You might create a macro that
    - Opens (instead of inserts) the ASCII file.
    - Copies the content to the clipboard.
    - Closes the ASCII file.
    - Does a Paste Special > Unformatted Text into the active document.

  3. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Insert File with unformatted text (Word 2002 SP-2)

    Thanks for the quick response. I thought maybe I'd be stuck with your suggested approach.

    Aside from the two issues I mentioned in my original post (applying the Plain Text style and using vbCrLf's instead of vbCr's), does anyone know of any other ways an inserted ASCII text file (using Insert File and the "Plain Text" option) will or may differ from pasting the same contents as unformatted text?

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Insert File with unformatted text (Word 2002 SP-2)

    As further follow-up, here's another approach that works -- i.e., it seems to cause the same result as a paste with unformatted text. (I don't really know if it's a better or worse approach. Thoughts, anyone?)

    Dim oRng As Word.Range
    Dim fso As Scripting.FileSystemObject
    Dim f As Scripting.File
    Dim ts As Scripting.TextStream
    Dim strX As String

    Set oRng = Selection.Range

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFile("MyFileOrYours")
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    strX = ts.ReadAll

    oRng.Text = strX

    ts.Close

    Set oRng = Nothing
    Set fso = Nothing
    Set f = Nothing
    Set ts = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •