VBA Macro to VBScript in a form- Help Please!

Status
Not open for further replies.

rhosyn18

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Ok so here's what I want to do. I have a custom form that creates an appointment which I invite others to attend from a shared calendar. I want the form to also send an email that is delayed by 2 days from the start date of the appointment, to the person that is invited (the required attendee) that is set within the form. I have a macro in outlook where I can select the appointment in the calendar and then run the macro and it will send the email. But I want the form to do it all (so my coworkers don't have to go into the calendar and select the appointment then run the macro). Can this be done? I'll include the VBA for the macro below. Thanks!

Code:
Sub mail() 
 
Dim obj As Object 
 
Dim Sel As Outlook.Selection 
 
Dim objAppt As Outlook.AppointmentItem 
 
Dim objOutlook As Object 
 
Dim objOutlookMsg As Object 
 
Set Sel = Application.ActiveExplorer.Selection 
 
Set objOutlook = CreateObject("Outlook.Application") 
 
Set objOutlookMsg = objOutlook.CreateItem(0) 
 
If Sel.Count Then  Set obj = Sel(1)

   If TypeOf obj Is Outlook.AppointmentItem Then
  
     Set objAppt = obj
     Set objTask1 = Application.CreateItem(olTaskItem) 
 
With objOutlookMsg
  .To = objAppt.RequiredAttendees
  .Subject = "Business Banking Follow up reminder: " & objAppt.Location
  '.Body = "This is the body of message"
  .HTMLBody = "Test message! " & "Company: " & objAppt.Location & " " & objAppt.Start
   dteThen = objAppt.Start + 2
  .DeferredDeliveryTime = dteThen
  '.Attachments.Add ("c:\myFileToSend.txt")
  .Send
 
 
End With 
 
End If 
 
End If 
 
On Error Resume Next 
 
Set objOutlookMsg = Nothing 
 
Set objOutlook = Nothing 
 
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
To make it automatic, you need to use an application start macro and an itemadd macro.

See Send an email when you add an appointment to your calendar - Slipstick Systems for the code.

This code would add it to your outbox. I have not tested it, but you might be able to add it to the form - you need to use a script and would use a

Function Item_Send()

Vbscript is slightly different from VBA so the code will need tweaked a little.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
If you wanted to use the script editor in a custom form (View code button), try this

Code:
Function Item_Send() 
 
Set MyApp = CreateObject("Outlook.Application") 
 
Set MyItem = MyApp.CreateItem(0) 'olMailItem 
 
With MyItem
  .To = Item.RequiredAttendees
  .Subject = "Business Banking Follow up reminder: " & Item.Location
  .Body = "Test message! " & Chr(13)  &  "Company: " & Item.Location &  Chr(13) & "Time: " & Item.Start
  .DeferredDeliveryTime =  Item.Start - 2
  '.Attachments.Add ("c:\myFileToSend.txt")
 ' .Send
   .Display 
 
End With 
 
End Function
 

rhosyn18

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Diane,

Thanks for the quick response! I tried the script below in the script editor in my custom form. I don't receive any errors and the script looks sound to me, but when I use the form to set an appointment, no email is sent or placed in my outbox. Any ideas why?

If you wanted to use the script editor in a custom form (View code button), try this

Code:
Function Item_Send() 
 
Set MyApp = CreateObject("Outlook.Application") 
 
Set MyItem = MyApp.CreateItem(0) 'olMailItem 
 
With MyItem
  .To = Item.RequiredAttendees
  .Subject = "Business Banking Follow up reminder: " & Item.Location
  .Body = "Test message! " & Chr(13)  &  "Company: " & Item.Location &  Chr(13) & "Time: " & Item.Start
  .DeferredDeliveryTime =  Item.Start - 2
  '.Attachments.Add ("c:\myFileToSend.txt")
 ' .Send
   .Display 
 
End With 
 
End Function
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Are you doing appointments or meeting requests? It works when you hit Send, not Save.
 

rhosyn18

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I'm setting an appointment. So here's what I did. I went to design mode for the form, view script, and added that script to the editor and published the form again. Then I do my usual, (tools, choose a form..etc) I set the time, add the invitees, etc. when i click send, the appointment itself sends, but the email doesnt get added to my outbox. Am I missing something?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Does the email display? I have the code set to show the message, change display to send and it will go into the outbox.
 

rhosyn18

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The email doesn't display, and I changed it to send instead of display and it still doesn't send. I can't find any reason as to why it isn't working.

Does the email display? I have the code set to show the message, change display to send and it will go into the outbox.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Are you using the exact same script I posted?

Check Tools, Trust center - Email security - is script in shared folders enabled? if you use run now which designing the form, it should work but you may need that set when it's published.
 

rhosyn18

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Diane,

This was not enabled at the time, I enabled it and it still isn't putting an email in the outbox or sending the email at all. I used the exact script that you posted. For testing purposes I am publishing this form to my personal calendar and testing it before I publish it to the shared calendar. Would that affect it?

Are you using the exact same script I posted?

Check Tools, Trust center - Email security - is script in shared folders enabled? if you use run now which designing the form, it should work but you may need that set when it's published.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
What addins are installed? I just had a guy tell me xobni prevents VBA from running. It worked when she disabled it, test the VBA, then re-enabled xobni.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
S VBA Macro to VBScript Outlook VBA and Custom Forms 1
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
R VBA macro - new message Outlook VBA and Custom Forms 3
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
Y VBA Macro to highlight some Keyword in mail body? Outlook VBA and Custom Forms 3
J Macro only runs within VBA Editor Outlook VBA and Custom Forms 2
D VBA macro printing attachments in shared mailbox Outlook VBA and Custom Forms 1
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
S Outlook 7 VBA macro for multiple filing Outlook VBA and Custom Forms 1
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
T Random problem in VBA macro Outlook VBA and Custom Forms 6
M recover deleted items vba macro Outlook VBA and Custom Forms 2
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
L VBA Macro to flag sent emails Using Outlook 1
B Outlook vba macro Using Outlook 1
B Auto BCC VBA macro: how to add exceptions? Using Outlook 28
D VBA Macro Works in 2007 but errors in 2010 Using Outlook 2
P VBA Macro for formatting multiple phone numbers in outlook contacts Using Outlook 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
E Word macro running from OL VBA throwing error on Word SaveAs?? Outlook VBA and Custom Forms 8
J Outlook custom form - VBS call VBA macro Outlook VBA and Custom Forms 3
N VBA Procedure (or Macro) to Stop Outlook from Closing? Outlook VBA and Custom Forms 2
M Run external program from Outlook VBA macro Outlook VBA and Custom Forms 5
D New Macro / VBA Outlook VBA and Custom Forms 7
J Specify Font Name or Face using VBA Macro in Word Outlook VBA and Custom Forms 2
S Custom VBA forms in Outlook--how to call w/macro? Outlook VBA and Custom Forms 1
S macro ist just worling wenn vba editor is open! Outlook VBA and Custom Forms 1
L VBA unknown character Outlook VBA and Custom Forms 2
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D.Moore VBA script fail after Office 365 update Using Outlook 8
Similar threads


















































Top