Mr.Petes
09-07-2011, 03:36 PM
Hi All,
I have created a form in VBA for rejecting certain work types. The purpose is to make it easy and time efficient for a specific business unit to reject bad applications etc.
The problem I am having is when the word doco is emailed all the fields have been reset (as they are populated by VBA code) to null values.
I am looking for a way to retain the field values intact so when the recipient open the mail the data is preserved.
I'm also having an issue where the userform_initialize isn't working whent he document starts?
Here is the code I am running:
Private Sub CmdBtnSendReject_Click()
Dim bStarted As Boolean
Dim OutlookApp As Outlook.Application
Dim Item As Outlook.MailItem
Dim TechLead As String
Dim TeamManager As String
Dim WorkPkgName As String
Dim projectName As String
Dim WpNumber As String
Dim newDelivery As Date
TechLead = cboTechLead.Value
TeamManager = cboTeamManager.Value
WorkPkgName = txtWPN.Value
projectName = txtProjectName.Value
WpNumber = TxtWPnumber.Value
newDelivery = DTPicNewDel.Value
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If
Set OutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set OutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set Item = OutlookApp.CreateItem(olMailItem)
With Item
.To = "randomemail@fakemail.comu"
'.CC = TechLead & ";" & TeamManager
.BCC = ""
.Subject = "Rejection of Work Package Notification: " & projectName & " : " & " " & WpNumber & " - " & WorkPkgName
.Body = "Please note the delivery of this Work Package has been delayed to: " & newDelivery & " if the workpackage is amended and resubmitted today"
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
OutlookApp.Quit
End If
Set Item = Nothing
Set OutlookApp = Nothing
End Sub
Any help appreciated.
-Petes
I have created a form in VBA for rejecting certain work types. The purpose is to make it easy and time efficient for a specific business unit to reject bad applications etc.
The problem I am having is when the word doco is emailed all the fields have been reset (as they are populated by VBA code) to null values.
I am looking for a way to retain the field values intact so when the recipient open the mail the data is preserved.
I'm also having an issue where the userform_initialize isn't working whent he document starts?
Here is the code I am running:
Private Sub CmdBtnSendReject_Click()
Dim bStarted As Boolean
Dim OutlookApp As Outlook.Application
Dim Item As Outlook.MailItem
Dim TechLead As String
Dim TeamManager As String
Dim WorkPkgName As String
Dim projectName As String
Dim WpNumber As String
Dim newDelivery As Date
TechLead = cboTechLead.Value
TeamManager = cboTeamManager.Value
WorkPkgName = txtWPN.Value
projectName = txtProjectName.Value
WpNumber = TxtWPnumber.Value
newDelivery = DTPicNewDel.Value
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If
Set OutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set OutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set Item = OutlookApp.CreateItem(olMailItem)
With Item
.To = "randomemail@fakemail.comu"
'.CC = TechLead & ";" & TeamManager
.BCC = ""
.Subject = "Rejection of Work Package Notification: " & projectName & " : " & " " & WpNumber & " - " & WorkPkgName
.Body = "Please note the delivery of this Work Package has been delayed to: " & newDelivery & " if the workpackage is amended and resubmitted today"
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
OutlookApp.Quit
End If
Set Item = Nothing
Set OutlookApp = Nothing
End Sub
Any help appreciated.
-Petes