The legal tricks-Learn Your Self

Latest gadgets,softwares,hardware,reviews,programming and campuses, game cheats ext......

Create and email a word document from ASP

Version Compatibility: ASP

More information: This example ASP subroutine will create a word document "on the fly" and email it, before deleting it from the server.

To email, the subroutine uses ASPMail (Free) from Flicks Software (www.flicks.com). You may replace it with any mail component you wish.

NOTE: You will have to change a number of hard coded values in the snippet below based on your needs. See the code's comments for places that require a change.

Instructions: Copy the declarations and code below and paste directly into your VB project

Sub CreateAppraisalForm(Manager,Email,Appraisee)

' CREATE WORD DOCUMENT

Set WordApp = CreateObject("word.application")
Set WordDoc = WordApp.Documents.Add()

WordApp.Application.Visible = False

Set MyRange1 = WordDoc.Paragraphs.Add.Range
MyRange1.InsertBefore("Appraisal Form")
MyRange1.Style = "Heading 1"

Set MyRange1 = WordDoc.Paragraphs.Add.Range
MyRange1.InsertBefore("Manager: " & Manager & vbcrlf & "Appraisee: " & Appraisee)
MyRange1.Font.Bold = true

Set MyRange1 = WordDoc.Paragraphs.Add.Range
MyRange1.InsertBefore(vbcrlf & "Please fill in all the required sections and return to HR via the internal mail system.")

' Set the directory location to store the generated documents
WordDocPath = Server.MapPath("\alastair\appraisals\forms")
' Use the unique session ID as the filename.
WordDoc.SaveAs WordDocPath & "\" & session.sessionID & ".doc"
WordDoc.Close
WordApp.Quit

Set WordDoc = Nothing
Set WordApp = Nothing

' EMAIL WORD DOCUMENT

Set mailer = Server.CreateObject("ASPMAIL.ASPMailCtrl.1")
recipient = Email
sender = "vance@ukonline.co.uk"
subject = "Requested Form"
message = "Please find the requested document attached."
attach = WordDocPath & "\" & session.SessionID & ".doc"
'INSERT YOUR MAIL SERVER HERE
mailserver = "xxx.xx.xx.xx"

result = mailer.SMAttach(mailserver, recipient, sender, subject, message, attach)

If result = "" Then

' DELETE WORD DOCUMENT FROM SERVER
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(WordDocPath & "\" & session.SessionID & ".doc")

Response.Write "The requested form will arrive in your inbox (email) within a few minutes. Please complete and return to HR asap."

Else
Response.Write "There has been an error sending the document to you." & vbcrlf
Response.Write "Right click the following link and select ""Save Target As..."" to retrieve the word document." & vbcrlf & vbcrlf
Response.Write "Generated Document" & vbcrlf & vbcrlf


End if

End Sub

0 comments: