Re: Getting MSW to convert txt to doc in vba
- From: Edward <Edward@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 14 Jan 2006 19:29:01 -0800
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.
>
.
- Follow-Ups:
- Re: Getting MSW to convert txt to doc in vba
- From: Jay Freedman
- Re: Getting MSW to convert txt to doc in vba
- References:
- Re: Getting MSW to convert txt to doc in vba
- From: Jay Freedman
- Re: Getting MSW to convert txt to doc in vba
- Prev by Date: Word vba Table
- Next by Date: Re: Getting MSW to convert txt to doc in vba
- Previous by thread: Re: Getting MSW to convert txt to doc in vba
- Next by thread: Re: Getting MSW to convert txt to doc in vba
- Index(es):
Relevant Pages
|
Loading