View Single Post
 
Old 11-21-2024, 06:47 AM
Casey Casey is offline Windows 10 Office 2021
Novice
 
Join Date: Nov 2024
Posts: 1
Casey is on a distinguished road
Default VBA for submit to email

Hi ,

I try to create a VBA where the 1st button goes to a email for authorisation, the approver then can send the form to accounts.

Code:
Private Sub CommandButton1_Click()
Dim xOutlookObj As Object
Dim xEmail As Object
Dim xDoc As Document
Application.ScreenUpdating = False
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmail = xOutlookObj.CreateItem(olMailItem)
Set xDoc = ActiveDocument
xDoc.Save
With xEmail
  .Subject = "Overtime Form"
  .Body = "Hi, please use email as approval for overtime; please process for month-end payroll."
  .To = "Accounts@............"
  .Importance = olImportanceNormal
  .Attachments.Add xDoc.FullName
  .Display
End With
Set xDoc = Nothing
Set xEmail = Nothing
Set xOutlookObj = Nothing
Application.ScreenUpdating = True
End Sub

End Sub
Private Sub CommandButton2_Click()

Dim xOutlookObj As Object
Dim xEmail As Object
Dim xDoc As Document
Application.ScreenUpdating = False
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmail = xOutlookObj.CreateItem(olMailItem)
Set xDoc = ActiveDocument
xDoc.Save
With xEmail
  .Subject = "Overtime Form"
  .Body = "Hi, please authorise and send to Accounts for payroll processing."
  .To = "overtime@........"
  .Importance = olImportanceNormal
  .Attachments.Add xDoc.FullName
  .Display
End With
Set xDoc = Nothing
Set xEmail = Nothing
Set xOutlookObj = Nothing
Application.ScreenUpdating = True
End Sub

it seems that the xDoc.Save is trying to save it after pressing the button to payroll???

Can someone please advise?

Thank you

Last edited by macropod; 11-21-2024 at 03:26 PM. Reason: Added code tags & formatting
Reply With Quote