Hi Ed,
Found the commented vb script below some time back - maybe in one of the
script NGs. If your programmer is determined to use PASCAL, this should give
him/her a few ideas.
Cheers
' havent really seen much in the way of windows scripts to create word
documents, so i coded this
' which can be modified to convert any file you want. just extend the array
boundries and add more
' entries and it should work. HAVE FUN!
Option Explicit
Private extension(1)
extension(0) = ".txt"
Dim objArgs, argc, spellchk, objFSO, path, objFolder, filecollection,
filename, objFile, i, ptr, wordin, wordfile, oDoc, myRange, stat, n, v
Set objArgs = WScript.Arguments
If objArgs.Count < 1 or objArgs.Count > 2 Then
Call Script_Error
End If
Wscript.echo "Text File conversion tool"
Wscript.echo "by James Lane"
wscript.echo ""
wscript.echo "Note: Formatting of files may be lost"
wscript.echo ""
argc = 0
spellchk = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Do While argc < CInt(objArgs.Count)
Select Case objArgs(argc)
Case "-s"
spellchk = 1
Case Else
If objFSO.FolderExists(objArgs(argc)) Then
path = objArgs(argc)
Else
Wscript.Echo "Folder does not exist."
Call Script_Error
End If
End Select
argc = argc + 1
Loop
Set objFolder = objFSO.GetFolder(path)
Set filecollection = objFolder.Files
For Each filename In filecollection
Set objFile = objFSO.GetFile(filename)
If objFile.Size > 0 Then
Set objFile = objFSO.OpenTextFile(filename, 1)
If ext(filename) Then
wordin = objFile.ReadAll
wscript.echo "File: " & filename
wscript.echo ""
wordfile = Left(filename, Len(filename) - 4) & ".doc"
Call makeword(wordfile, wordin, spellchk)
wscript.echo ""
End If
End If
Next
Sub Script_Error
WScript.Echo ""
WScript.Echo "Converts txt files to word documents"
WScript.Echo ""
WScript.Echo "Usage: word.vbs [-s] folder"
WScript.Echo ""
WScript.Echo "Options : "
WScript.Echo ""
WScript.Echo " -s Runs a SpellCheck on the files as they are
converted"
WScript.Echo ""
WScript.Quit
End Sub
Sub makeword(file, content, spellchk)
Set oDoc = CreateObject("Word.Document")
oDoc.Content = content
If spellchk = 1 Then
oDoc.CheckSpelling
oDoc.CheckGrammar
Set myRange = oDoc.Content
For Each stat In myRange.ReadabilityStatistics
n = stat.Name
v = stat.Value
Wscript.Echo "" & n & " : " & v & ""
Next
End If
oDoc.SaveAs file
wscript.sleep 1000
oDoc.Close
Set oDoc = Nothing
End Sub
Function ext(filename)
For i = 0 to (UBound(extension) - 1)
ptr = InstrRev(filename, extension(i), -1, 1) - 1
If (ptr + Len(extension(i))) = Len(filename) Then
ext = true
Exit For
Else
ext = false
End If
Next
End Function
Ed said:
One of our programmers working with a PASCAL database wants to know if "we"
can get his text file output onto a landscaped Word page. I can do a
template and code for whatever he wants. But does anyone know if PASCAL can
reach out and create a new Word doc based on a specific template? We're
just trying to eliminate some manual steps.
Ed