Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access controlling Word to create TXT file (2000)

    In order to have Access read the lines of a Word file, I have Word save the file as a text file.

    The problem is that I can't seem to get the right code to have Word save the text file without all the formatting gibberish throughout the document.

    I am using the following code, where 'mydocname' is a variable which contains the filename:

    WordApp.ActiveDocument.SaveAs FileName:=mydocname, FileFormat:=wdFormatTextLineBreaks, _
    EmbedTrueTypeFonts:=False

    When I use exactly the same code (minus 'wordapp.') in Word, it works fine. But from Access, I get all the formatting junk.

    How can I resolve this? I have tried saving as a DOS text file, but no good.

    Thanks very much in advance!

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Access controlling Word to create TXT file (2000)

    Hi,
    Just a quick thought - do you have a reference set to the Word Object library? If not, then you'll probably find that the wdFormatTextLineBreaks constant has a value of 0 (because Access doesn't know what it is), which is the equivalent of wdFormatDocument to Word. If you replace wdFormatTextLineBreaks with 3 does that help? If you do have the reference set, try changing the constant to Word.wdFormatTextLineBreaks and see if that does the trick.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access controlling Word to create TXT file (2000)

    Thank you - I did not have a reference set to the Word Object library - fixed the problem instantly.
    Much appreciated!

Posting Permissions

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