Re: Getting MSW to convert txt to doc in vba



that worked great. One other problem encountered:

I tried to give the msw file the same name as the text file by this:
For i = 1 To fs.FoundFiles.Count
textfilename = fs.FoundFiles(i)
then I assign textfilename as the filename. Problem is, textfilename
includes the .txt extension, so even though the file is a word file, it winds
up having a .txt extension. It retains its header and footer info implanted
by the macro.
I suppose I could open a dos window and change all the .txt to .doc, but
this shouldn't be necessary. Is there a way to get the filename without the
..txt extension relic from the text file?

I would try to truncate the characters, but can't find the corresponding
search phrase in the help file
--
Phantom Researcher


"Jay Freedman" wrote:

> On Fri, 13 Jan 2006 18:18:03 -0800, Edward
> <Edward@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> >I have a subdirectory of text files that I need to convert to MSW. During
> >the conversion, I want to run a macro that adds headers and footers to each
> >file.
> >
> >My approach is to write in VBA for Word. I don't have a problem locating
> >the files in the subdirectory, and have a count algorithm that works.
> >
> >My problem is that I can't seem to open an existing text file as a word
> >document so that I can run my header/footer macro, then close the file and
> >save it in MSWord format.
> >
> >Am I supposed to be opening a text file , then running the macro and saving
> >it as a Word file, or am I supposed to be opening a Word file and reading the
> >text file into it, then running the macro, then saving as a Word file?
> >
> >There's lots of stuff in VB that allows developers to build text files, but
> >nothing I see that talks about this kind of conversion.
> >
> >Thanks.
> >
> >Phantom Researcher
>
> Hi Edward,
>
> Really, you can do the job either way. In the end it makes no
> difference in the finished document.
>
> If your macro instructs Word to open a .txt file, Word creates a
> document in memory and places the text in the body of the document. At
> this point it's like any other document in memory. You can add
> information to the header and footer. Then do a SaveAs, giving a
> different filename (if only to change the extension to .doc) and
> including the parameter FileFormat:=wdFormatDocument. (The latter is
> necessary because if you omit it, Word defaults to saving the document
> in its original .txt format, and that would cause it to display a
> warning that the formatting -- the header and footer -- would be
> lost.) Read the VBA help topic on the SaveAs method to see the
> possible parameter values.
>
> Alternatively, you can instruct Word to make a new blank document, and
> use the InsertFile command to bring in the text file. After adding the
> header and footer, you do a SaveAs; in this case it will assume a
> default file format of wdFormatDocument, although it wouldn't hurt to
> include that parameter anyway.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
>
.



Relevant Pages

  • Re: Print word document without header and footer
    ... The macro works really well apart from the fact that the header still prints ... Microsoft Word MVP ... you can just select a box etc to not print the the header and footer. ...
    (microsoft.public.word.docmanagement)
  • Re: graphic is in the doc and prints, but cant find to delete
    ... I've checked the header and footer (we use neither in this ... I hope someone can write a macro that we can use to find and eliminate the ... Microsoft MVP (Word) ...
    (microsoft.public.word.drawing.graphics)
  • Re: Header footer toolbar missing
    ... You could, however, try to install and run the macro ... 'Enable and show "Header and Footer" toolbar ... With CommandBars("Header and Footer") ...
    (microsoft.public.word.pagelayout)
  • Re: changing code to also copy the header and footer 2 saved docs
    ... the header and footer are being deleted. ... separate file, the header and footer are missing in the separated files. ... ' MailMergeLetterSplitter Macro ...
    (microsoft.public.word.vba.general)
  • Word 2007
    ... file path & extension of any document either as a header or footer without ...
    (microsoft.public.mac.office)

Loading