SHARE
Facebook X Pinterest WhatsApp

ASP and Word

Jul 20, 2010
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

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
What Is a Network Policy Server (NPS)? | Essential Guide
Virtual Servers vs. Physical Servers: Comparison and Use Cases
Ray Fernandez
Nov 14, 2023
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.