Re: Newbie: Saving as Word doc
From: MikeD (nobody_at_nowhere.edu)
Date: 03/27/04
- Next message: MikeD: "Re: Refering to From of ActiveX DLL"
- Previous message: Bob O`Bob: "Re: Installing DLLs & avoiding problems!"
- In reply to: Ed: "Newbie: Saving as Word doc"
- Next in thread: Ed: "Re: Newbie: Saving as Word doc"
- Reply: Ed: "Re: Newbie: Saving as Word doc"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 26 Mar 2004 20:28:26 -0500
"Ed" <ed_millis@removethis.hotmail.com> wrote in message
news:%23Z9OWv0EEHA.3784@TK2MSFTNGP10.phx.gbl...
> Well, my first attempt at fixing this thing didn't work, so I'm trying
> again. I've inherited a VB app that experts here say is poorly written.
I
> can believe it! Plus, I'm not real hot at programming, so I don't always
> understand exactly what's going on. This VB app opens up text files in
> Word, splits them into separate documents, and saves each new document
into
> a folder with a " .doc" extension.
>
> I have discovered that just because the new docs are saved with " .doc",
and
> Word sees and opens them just fine, they are *not* necessarily Word docs,
> with real Word formatting. This means some of my Word macros (like search
> tools, etc.) don't work because they can't "see" what they need to key off
> of.
This is true. Merely changing a file's extension does NOT "convert" that
file to a different format. In fact, it doesn't change the file at all. It
just means the file may be opened with a different application (and the
application has to support the file's format). What you're ending up with
is just a regular old text file that just *happens* to have a .doc
extension. Just reminiscing....in the DOS days, it was very common for text
files to have this extension (README.DOC files were *very* common).
Personally, I don't know why MS ever chose .doc as the extension for Word
document files as many other types of applications have "document" files
(fortunately, they didn't choose .dat for Access database files; that would
have REALLY fubared things).
>
> I added code to the VB app to run after the separation part is finished
that
> goes back into the folder, opens every doc, and resaves it as a Word doc.
I
> have over 12,000 docs, though, and after 30 minutes and it still wasn't
> done, I figured there had to be a better way - like get it to save as a
Word
> doc the *first* time, rather than do it again. But, like a newbie, I
don't
> know how to change the code to do that.
>
> This appears to be the current Save process:
> ' get text cut from long doc
> Set fil = fso.GetFile("c:\tempfile.txt")
> Count = Count + 1
> ' save into folder as " .doc"
> fil.Copy ("c:\TIR\" & tempfile & ".doc")
> tempfile = " "
>
> This is what I've added:
> fldr2 = "c:\TIR " & dates & "\"
> Set WordApp = CreateObject("Word.Application")
> strFName = Dir$(fldr2 & "*.*")
> Do While Len(strFName) > 0
> If StrComp(Right$(strFName, 4), ".doc", vbTextCompare) = 0 Then
> Set WordDoc = WordApp.Documents.Open(fldr2 & strFName)
> WordDoc.SaveAs FileName:=fldr2 & strFName, _
> FileFormat:=wdFormatDocument
> WordDoc.Close
> End If
> strFName = Dir$
> Loop
> Set WordDoc = Nothing
> Set WordApp = Nothing
>
> Any help merging the two processes and shortening my run time is greatly
> appreciated!
Well, you could get rid of the first part (which merely copies the file with
a different extension). Just open the .txt file directly, using your
Word.Application object. Other than that, there's probably not anything
different you can do to convert the text format file to a Word format file
(unless you want to get into the messy Word file format and write the file
"from scratch"). In all probability, that'd probably be considerably quicker
than using Automation with Word, but also a LOT more difficult.
Two other things that I see with your code:
1. NEVER hard-code paths.
2. You're not quitting Word. Setting the object variable for the
Word.Application object does not cause Word to quit. You need to call its
Quit method. You're closing the document and that's good, but you're not
quitting the Word application instance you've created.
Mike
- Next message: MikeD: "Re: Refering to From of ActiveX DLL"
- Previous message: Bob O`Bob: "Re: Installing DLLs & avoiding problems!"
- In reply to: Ed: "Newbie: Saving as Word doc"
- Next in thread: Ed: "Re: Newbie: Saving as Word doc"
- Reply: Ed: "Re: Newbie: Saving as Word doc"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|