ServersASP and Word

ASP and Word

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.




by Armand Datema

Here is a new tutorial on how to write to a word document, change the contents of a word
document and print it out. There will also be an update to
this one and the excel one with more things you can do. Most
of it comes from the the microsoft office VB help. But you
have to do some fiddling with the code to get the VBscript
code.

Here is a new tutorial on how to write to a word document, change the contents of a word
document and print it out.

First we set the type of script

Make the object, and set the object to a word document

Dim MyDoc
Set
MyDoc =
CreateObject(“Word.Document”)
MyDoc.Application.Visible =
True

Now lets write the rest of the script, see the comments

‘ Set the font
properties
MyDoc.content.Font.Bold =
True
MyDoc.content.Font.Italic =
True
MyDoc.content.Font.Underline =
True
MyDoc.content.Font.Name = “Comic Sans
MS”
MyDoc.content.Font.Size = 25

‘ Insert some
text
MyDoc.content.insertAfter “word1 word2 word3
word4”
MyDoc.content.InsertParagraphAfter

‘ Now lets change
the colors and fontsize of the induvidual words that were just
added, just look closely to the opened word document and you
will see it change dynamically
MyDoc.Words(1).Font.Size =
10
MyDoc.Words(1).Font.ColorIndex =
1
MyDoc.Words(2).Font.Size =
20
MyDoc.Words(2).Font.ColorIndex =
2
MyDoc.Words(3).Font.Size =
30
MyDoc.Words(3).Font.ColorIndex =
3
MyDoc.Words(4).Font.Size =
40
MyDoc.Words(4).Font.ColorIndex =
4

‘ Print the
document
MyDoc.PrintOut
‘ Release the object
variable.
Set MyDoc = Nothing

%>

Now lets complete
the HTML tags.

Excelface

This completes yer ASP page,
look below for the complete code of
mydoc.asp


Dim MyDoc
Set MyDoc =
CreateObject(“Word.Document”)
MyDoc.Application.Visible =
True
MyDoc.content.Font.Bold =
True
MyDoc.content.Font.Italic =
True
MyDoc.content.Font.Underline =
True
MyDoc.content.Font.Name = “Comic Sans
MS”
MyDoc.content.Font.Size =
25
MyDoc.content.insertAfter “word1 word2 word3
word4”
MyDoc.content.InsertParagraphAfter
MyDoc.Words(1).Font.Size
= 10
MyDoc.Words(1).Font.ColorIndex =
1
MyDoc.Words(2).Font.Size =
20
MyDoc.Words(2).Font.ColorIndex =
2
MyDoc.Words(3).Font.Size =
30
MyDoc.Words(3).Font.ColorIndex =
3
MyDoc.Words(4).Font.Size =
40
MyDoc.Words(4).Font.ColorIndex =
4
MyDoc.PrintOut
Set MyDoc = Nothing

%>

Download Code

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories