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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript in outlook

Status
Not open for further replies.

SteT01

Programmer
Joined
Nov 1, 2006
Messages
5
Location
GB
new to VBScipt and trying to build a form that with one button will validate and then send the Data

the problem i am having is actually getting the object/Form in the first place, i am using the script editor but am unaware of the Dim statements & Syntax needed. and as you will probably know the Script editor gives very little help!!
 
if you could get me started on how to go about it i will use VBA
 
Not exactally sure of what your trying to do other then create an email. The following code will create an email.

Code:
Option Explicit

 ' Subroutine Creates an email, addresses it, attaches file, and sends it.
Sub AttachmentEmail()

Dim oNewMail As Object
Dim oAttachments As Object
Dim sDirectory As String
Dim sFileToSend As String
Dim sMsgBody As String

'Path to the sDirectory where the file is located
'You will have to put in a valid path (make sure you include the quotes around the path)
sDirectory = "C:\Documents and Settings\<user name>\My Documents\"

'Name of the file you want to attach
'sFileToSend = "<name of the file you want to send>"

' Text that will go in the message body
sMsgBody = "This message was generated with Visual Basic for Applications"
' Concatenate a carriage return/line feed to the message body
sMsgBody = sMsgBody & vbCrLf

'creates a new email
Set oNewMail = ThisOutlookSession.CreateItem(olMailItem)

'Fill in the subject field
oNewMail.Subject = "Whatever your subject is"

' Fill the 'To', 'CC' and 'BCC' fields
oNewMail.To = "somebody@somesystems.com"
oNewMail.CC = "anybody@anysystems.com"
oNewMail.BCC = "nobody@nowhere.com"

' Insert the message in the body
oNewMail.Body = sMsgBody

' Attach file to email
Set oAttachments = oNewMail.Attachments
        
        'This concatinates the sDirectory with the file name
        oAttachments.Add sDirectory & sFileToSend

' Makes the new email visible
oNewMail.Display

' Remove the quote and oNewMail.Send will send the email
' oNewMail.Send

' Clean up
Set oAttachments = Nothing
Set oNewMail = Nothing

End Sub

Open up the Visual Basic editor (alt + F11) and insert a module. Copy and paste the code into the module. To run the code press F5 or press F8 to single step through the code.
 
Another note:

If you want to just run through part of the code, but step through a latter portion (for instance, so you don't have to run over and over through a loop - if you have any in any code you use), then you can left click to the left of a line (not a Dim statement) where you want to stop normal execution, allowing you to step through the remainder of the code. By doing this, you'll see that line highlighed in sort of a dark red (there is probably a more defined color, but I can't think of a name). Then, when you run the code, it will run until it reaches that line (not unto), and stop there, allowing you to step through the rest of it.

You can hit F5 after stepping through any portion to continue strait on to the end.

Then, if you want specific VBA help after that, you might find more help (possibly) in the following forum:

VBA Visual Basic for Applications (Microsoft) Forum - forum707
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top