Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA help addingattachment to email

Status
Not open for further replies.

dippncope

Technical User
Sep 22, 2008
88
US
Hello, I need some help with my HTA. It creates a tsv file on the users desktop named "username" inventory.tsv using text entered. A second button creates an outlook email. The problem I am having is adding the tsv file as an attachment. Please explain how I can add the atachment using variables of user desktop and user name to add the tsv created.


Here is my HTA
Code:
<html>
<head>
<body STYLE="font:14 pt arial; color:white;
 filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000000', EndColorStr='#0000FF')">
<style type="text/css">
.label{ width: 150px; overflow: none; display: inline;}
</style>

<title>Inventory</title>
</head>

<SCRIPT Language="VBScript">
       
    Sub SaveData
    Dim sNow : sNow = CStr( Now )
 teNow.value = sNow
	Set oShell = CreateObject("WScript.Shell") 
	'User's Desktop for deploying shortcuts. 
    	sDesktop = oShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\" 
'get user name for file
Dim objNet
 Set objNet = CreateObject("WScript.NetWork")
       'end get username 
        Set objFSO = CreateObject("Scripting.FileSystemObject")
                If objFSO.FileExists(objNet.UserName & "'s inventory.tsv") Then
               
           Set objFile = objFSO.OpenTextFile(objNet.UserName & "'s inventory.tsv", 8)
           
          
           
            strLine = UserName.Value & vbTab & Asset.Value & vbTab & SN.Value & vbTab & _
                AssetType.Value & vbTab & Building.Value & vbTab & Floor.Value & vbTab & _
                 Tech.Value & vbTab  & teNow.Value & vbTab
            objFile.WriteLine strLine
            objFile.Close
        Else
            Set objFile = objFSO.CreateTextFile(objNet.UserName & "'s inventory.tsv")
            
            
            strLine = UserName.Value & vbTab & Asset.Value & vbTab & SN.Value & vbTab & _
                AssetType.Value & vbTab & Building.Value & vbTab & Floor.Value & vbTab & Tech.Value & vbTab  & teNow.Value & vbTab
            objFile.WriteLine strLine
            objFile.Close
        End If
    End Sub
 
 'compose email
Sub sendemail 
'get username
Dim objNet
 Set objNet = CreateObject("WScript.NetWork") 
'end get username

 Dim oLapp
Dim oItem
Set oLapp = CreateObject("Outlook.application")
Set oItem = oLapp.CreateItem(0)
With oItem
.Subject =   objNet.UserName & "'s Inventory: "
.To = "email1@abc.com;email2@xyz.com"
.Body = objNet.UserName & "'s Inventory as of " & Now()

.display

Set oLapp = Nothing
Set oItem = Nothing
 End With
End Sub
'end email


</SCRIPT>

<body>
   <span class="label"> User Name:</span><input type="text" name="UserName" size="25"><p>
   <span class="label">Asset Tag:</span><input type="text" name="Asset" size="25" ><p>
   <span class="label">Serial Number:</span><input type="text" name="SN" size="25"><p>
   <span class="label">Type:</span><input type="text" name="AssetType" size="25"><p>
   <span class="label">Building:</span><input type="text" name="Building" size="25"><p>
   <span class="label">Floor:</span><input type="text" name="Floor" size="25"><p>
   <span class="label">Technician</span><input type="text" name="Tech" size="25"><p>
   <span class="label">Date</span><input id = "teNow" type = "TEXT" size = "25" value = ""><p>
    <input type="button" value="Update Inventory" onClick="SaveData">
    <input type="button" value="Send Email" onClick="sendemail">
    <input type="button" value="Close" onClick="Close">
    
</body>
 
...
.Body = objNet.UserName & "'s Inventory as of " & Now()
.Attachments.Add objNet.UserName & "'s inventory.tsv", 1
.Display
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
Perfect thank you. I tried that without the ,1 and it failed and then I confused myself even more.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top