Link to home
Start Free TrialLog in
Avatar of Sambob
Sambob

asked on

Formatting MS Word text after opening.

Hi,
I have been given the task of loading a message into Word which is in gold font(I guess yellow would do). I can open Word no problem but I can't find any information about formatting the text to go inside. The script I am using is

<% @LANGUAGE = VBScript %>
<%
Response.ContentType = "application/msword"
Response.Expires = 0
%>
Message text would appear here (but where do I put the formatting?).

Thanks in advance

Sam
ASKER CERTIFIED SOLUTION
Avatar of Michel Sakr
Michel Sakr
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sambob
Sambob

ASKER

The books I have been looking at suggest that HTML tags would be displayed along with the text so I didn't even bother trying that approach. I'll have a look in the morning and award you the points if all is OK.
Thanks
Sam
Sambob,

If I understand what you are trying to do, the scripting host will continue to use the "context" you opened up with your command Response.ContentType. That is, it will essentially "open" MS Word in your browser window. Thus, to get a message in a particular color, you could use the Write method of the Response object. So, if I want to have a formatted message, I would use something like the following:

<%
Response.Write "<font color='blue'>This is the one!</font>"
%>

This puts your formatting in-line and lets Word receive the output of the Response object. This will allow you to use all the VBScripting power to format and use variables to create your message.

If you want just plain simple, just embed standard HTML after your ASP command close marker (the %> sign) and Word will interpret it directly. So, in this case, it would look like:

<% @LANGUAGE = VBScript %>
<%
Response.ContentType = "application/msword"
Response.Expires = 0
%>
<font color='blue'>This is the one!</font>.

To show you both, I have composed a little ASP that has both methods (although I don't use any real features of VBScript, it does illustrate the point):
<html>
<!-- Creation date: 6/18/2002 -->
<head>
<title>ASP and Word Demonstration</title>
<meta name="description" content="Demonstration of Word Control from ASP">
<meta name="author" content="sphillips77">
</head>
<body>
<% @LANGUAGE = VBScript %>
<%
Dim strMsg
     strMsg     =     "Message from VBScript!"
     
Response.ContentType = "application/msword"
Response.Expires = 0
Response.Write "<center><h1><font color='blue'>" + strMsg + "</font></h1></center>"
Response.Write "<br><hr><br>"
Response.Write "<p align='center'><font color='green'>Brought to you by MS Scripting Host</font></p>"
%>
<br><hr><br>
<center><h1><font color='blue'>Your plain HTML message here.</font></h1></center>
<p align='center'><font color='green'>Brought to you by MS Scripting Host</font></p>

</body>
</html>

I hope this helps.
sandyphillips, welcome to EE.
:)

The practice here is not to propose an answer, unless you are:
- first to suggest an answer
- totally covering the subject, leaving nothing more to say

The reason for this is that when you propose an answer, the question is moved to the Locked Questions. That means that few experts will even look at it, so the person asking the questions will probably not getting any more input. That's not really fair to him.

Please read the tips on comments and answers below.
Avatar of Sambob

ASKER

sandyphillips,
sorry! the question had already been answered adequately by Silvers5 but thank you for answering anyway,
Sam
Avatar of Sambob

ASKER

How do I now award the points to Silvers5?
Sam