Word VBA and OLE Server

T

Tony

Hello everyone,

I'm very new to programming, ColdFusion and VBA, so I have (what I
hope is) a simple question.


I'm calling a word macro from ColdFusion, and apparently to do that I
need to run word as an OLE Server. What does it mean to run word as an
OLE server and how do I do that?

Thanks everyone.

-- Tony
 
P

Peter Hewett

Hi Tony

Isn't ColdFusion is a scripting language like ASP, PHP? If that's the case and your
creating a script then your using VB script rather than VBA. VB script is to VBA, what
VBA is to VB. They're essential language subsets with implementation differences.

I'm also presuming that this is not server side scripting.

Since I know squat about ColdFusion I'll stick to VB Script. Here's how you can use Word
from VB Script:

Here's a simple script that will print a Word document:

Option Explicit

Dim wdApp
Dim docNew
Dim objArgs
Dim strDocument
Dim strOriginalPrinter

' Get the command line arguments
Set objArgs = WScript.arguments
If objArgs.Count = 0 Then
MsgBox "You must supply the name of the file to print"
WScript.Quit (1)
Else
strDocument = objArgs.Item(0)
End If

' Create WOrd application object
Set wdApp = WScript.CreateObject("Word.Application")
With wdApp.Application

' Open the specified document so that we can print it
Set docNew = .Documents.Open(strDocument)

' Save the active printer so tha twe can restore it
strOriginalPrinter = .ActivePrinter
.ActivePrinter = "Print-2-Image"

' Print the document
docNew.PrintOut False, False, 0, "e:\Test.prn", , , 0, 1, "", 0, True, False, "",
False, 0, 0, 0, 0

.ActivePrinter = strOriginalPrinter
docNew.Close 0 ' 0 = wdDoNotSaveChanges

' Finished with Word...
.Quit
End With
Set wdApp = Nothing

HTH + Cheers - Peter


(e-mail address removed) (Tony), said:
 
T

Tony

Peter Hewett said:
Hi Tony

Isn't ColdFusion is a scripting language like ASP, PHP? If that's the case and your
creating a script then your using VB script rather than VBA. VB script is to VBA, what
VBA is to VB. They're essential language subsets with implementation differences.

I'm also presuming that this is not server side scripting.

Since I know squat about ColdFusion I'll stick to VB Script. Here's how you can use Word
from VB Script:

Here's a simple script that will print a Word document:

Option Explicit

Dim wdApp
Dim docNew
Dim objArgs
Dim strDocument
Dim strOriginalPrinter

' Get the command line arguments
Set objArgs = WScript.arguments
If objArgs.Count = 0 Then
MsgBox "You must supply the name of the file to print"
WScript.Quit (1)
Else
strDocument = objArgs.Item(0)
End If

' Create WOrd application object
Set wdApp = WScript.CreateObject("Word.Application")
With wdApp.Application

' Open the specified document so that we can print it
Set docNew = .Documents.Open(strDocument)

' Save the active printer so tha twe can restore it
strOriginalPrinter = .ActivePrinter
.ActivePrinter = "Print-2-Image"

' Print the document
docNew.PrintOut False, False, 0, "e:\Test.prn", , , 0, 1, "", 0, True, False, "",
False, 0, 0, 0, 0

.ActivePrinter = strOriginalPrinter
docNew.Close 0 ' 0 = wdDoNotSaveChanges

' Finished with Word...
.Quit
End With
Set wdApp = Nothing

HTH + Cheers - Peter


(e-mail address removed) (Tony), said:

Peter,

Thank you for this reply. I am rather confused and I think it would be
best if I start with an even more simple question:

What does it mean to run MS Word as an OLE server?

Thanks everyone.

-- Tony
 
P

Peter Hewett

Hi Tony

OLE has been supplanted by COM. In COM an object (Library, Application) exposes its
Methods and Properties so that you can interact and manipulate the exposed object(s). In
OLE, which predates COM one application controls another as would a user - by sending
keystrokes to it! In the Word 6 days you might have a document with an embedded Excel
worksheet. You could activate it, which would start Excel, but to edit it you had to send
keystrokes to Excel!

HTH + Cheers - Peter


(e-mail address removed) (Tony), said:
 
T

Tony

Peter Hewett said:
Hi Tony

OLE has been supplanted by COM. In COM an object (Library, Application) exposes its
Methods and Properties so that you can interact and manipulate the exposed object(s). In
OLE, which predates COM one application controls another as would a user - by sending
keystrokes to it! In the Word 6 days you might have a document with an embedded Excel
worksheet. You could activate it, which would start Excel, but to edit it you had to send
keystrokes to Excel!

HTH + Cheers - Peter


(e-mail address removed) (Tony), said:

Thank you very much Peter, that helps a lot.
 

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