web 2.0

How to use ASP & Word (Word.Application) - Open Document (Documents.Open)

How to use ASP & Word (Word.Application) - Open Document (Documents.Open) This is learn/tutorial asp developers how to using ASP script Open word document and write text into same document.

ShotDev Focus:
- ASP & Open word document and write text into same document.

ASP & Open word document and write text into same document.

Example

asp_word_template.asp


<% OptionĀ  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Const wdAlignParagraphCenter = 1

Dim Wrd,WrdDoc,DocName
Dim MyRange1
Set Wrd = CreateObject("Word.Application")
DocName = "MyDoc/MyWord.doc"
Wrd.Application.Visible = False

Set WrdDoc = Wrd.Documents.Open(Server.MapPath("shotdev.dot"))

Set MyRange1 = WrdDoc.Range()
With MyRange1
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Name = "Verdana"
.Font.Size = "30"
.Font.Bold = True
.InsertBefore(vbCrLf&vbCrLf&"www.ShotDev.Com"&vbCrLf&"Version 2010"&vbCrLf)
End With

Set MyRange1 = WrdDoc.Paragraphs.Add.Range
MyRange1.InlineShapes.AddPicture Server.MapPath("logo.gif")

Set MyRange1 = WrdDoc.Paragraphs.Add.Range
With MyRange1
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Name = "Verdana"
.Font.Size = "13"
.Font.Bold = True
.InsertBefore(vbCrLf&vbCrLf&vbCrLf&vbCrLf&"All Rights Reserved.")
End With

WrdDoc.SaveAs(Server.MapPath(DocName))
Wrd.Application.Quit
Set Wrd = Nothing
%>

Word Created <a href="<%=DocName%>">Click here</a> to Download.
</body>
</html>

Create a asp file and save to path root-path/myasp/

Run
http://localhost/myasp/asp_word_template.asp

Screenshot

ASP & Open word document and write text into same document.
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.