Controlling Word via PASCAL?

E

Ed

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
 
M

macropod

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
 
E

Ed

Thank you. I will pass it on to him. It's not so much that he's
*determined* to use PASCAL - he *HAS* to. It's an old system - early to mid
80's, I think, and PASCAL is the native language of the database program.
Literally EVERYTHING is on there, and it's not easily transferable (so they
tell me). So, until it dies and they are forced to replace the entire
setup, they won't!

In the meantime, I'll stick with VBA - it's giving me enough fits! 8>)

Ed

macropod said:
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
 
T

Tom Winter

Its going to depend on the capabilities of the database program and its
implementation of Pascal. Since it is so old, its not going to support COM
so you can't do any kind of direct automation. If the Pascel can "run"
another program, that might give you a chance. Have Pascal run that program
(written in a modern language) and then have it do what you want.
--
Tom Winter
(e-mail address removed)
www.AmosFiveSix.com
Ed said:
Thank you. I will pass it on to him. It's not so much that he's
*determined* to use PASCAL - he *HAS* to. It's an old system - early to mid
80's, I think, and PASCAL is the native language of the database program.
Literally EVERYTHING is on there, and it's not easily transferable (so they
tell me). So, until it dies and they are forced to replace the entire
setup, they won't!

In the meantime, I'll stick with VBA - it's giving me enough fits! 8>)

Ed

macropod said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top