fredlo2010
08-16-2013, 07:14 AM
Hello,
I am trying to create a Macro to send a word document as an attachment.
I used the code provided in this place (http://www.howto-outlook.com/howto/senddocasmail.htm) and I am trying to modify it a little to fit my needs.
I need to create variables for the subject that will change with every single document. The problem is that the email come up with only one variable and not the second.
For example the subject should be: "Customer Reference" and it shows as "Customer" ran through the code (F5) and the variable is taking the correct value.
This is the code I am using
Sub SendDocAsMail()
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Start Outlook if it isn't running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
End If
'Create a new message
Set oItem = oOutlookApp.CreateItem(olMailItem)
'Display the message
Dim companyName As String
Dim refNumber As String
Dim varsub3 As String
'SET THE COMPANY NAME
ActiveDocument.Tables(1).Columns(2).Cells(1).Range.Select
companyName = Selection.Paragraphs(2).Range
'SET THE REFERENCE NUMBER NAME
refNumber = ActiveDocument.Tables(1).Columns(1).Cells(1).Range
oItem.Subject = companyName & refNumber
oItem.Display
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Set objInsp = Nothing
Set wdEditor = Nothing
End Sub
Thanks a lot for the Help :)
I am trying to create a Macro to send a word document as an attachment.
I used the code provided in this place (http://www.howto-outlook.com/howto/senddocasmail.htm) and I am trying to modify it a little to fit my needs.
I need to create variables for the subject that will change with every single document. The problem is that the email come up with only one variable and not the second.
For example the subject should be: "Customer Reference" and it shows as "Customer" ran through the code (F5) and the variable is taking the correct value.
This is the code I am using
Sub SendDocAsMail()
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Start Outlook if it isn't running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
End If
'Create a new message
Set oItem = oOutlookApp.CreateItem(olMailItem)
'Display the message
Dim companyName As String
Dim refNumber As String
Dim varsub3 As String
'SET THE COMPANY NAME
ActiveDocument.Tables(1).Columns(2).Cells(1).Range.Select
companyName = Selection.Paragraphs(2).Range
'SET THE REFERENCE NUMBER NAME
refNumber = ActiveDocument.Tables(1).Columns(1).Cells(1).Range
oItem.Subject = companyName & refNumber
oItem.Display
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Set objInsp = Nothing
Set wdEditor = Nothing
End Sub
Thanks a lot for the Help :)