Reputation: 159
Very new to VBA, just starting to learn! Been getting interested in the possibilities of vba macros and was wondering if it is possible to bulk send approximately 100 emails in my draft box in ms outlook?
Haven't tried anything significant yet so really just looking for start points so I can develop it on my own! Was thinking of starting with a box prompt too,
so I have this code for that
Sub bulksend()
If MsgBox("send all drafts?", vbquestion + vbyesno) <> vbyes then exit sub
End sub
Any help on this but also how i can learn more vba is greatly appreciated :)
Upvotes: 2
Views: 868
Reputation: 600
Welcome to VBA, i'm quite new too but have learnt alot over the last couple of months. I find that just getting stuck in and using internet resources such as SO is best for me, but there's probably loads of good books out there if you like to learn that way!
Believe it or not I actually covered this when I was in the same situation as you about a month ago :) This code Works but I encourage you to step through it to really understand what it does as that's the best way to learn new code. Not sure if you know about outlook vba but to use this open vba through outlook (ALT + F11). In the projects box top left open project1, then Microsoft Outlook Objects and ThisOutlookSession, Paste the code in and press F5. To step through each line press F8. Let me know how it goes and good luck learning :)
Private Declare Sub Sleep Lib "kernel32" (ByVal nMilliseconds As Long)
Sub SendAllDrafts()
If MsgBox("Send all drafts??", _
vbQuestion + vbYesNo) <> vbYes Then Exit Sub
Dim fldDraft As MAPIFolder, msg As Outlook.MailItem, intCount As Integer
Set fldDraft = Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)
intCount = 0
Do While fldDraft.Items.Count > 0
Set msg = fldDraft.Items(1)
msg.Send
Sleep 1000
intCount = intCount + 1
Loop
If Not (msg Is Nothing) Then Set msg = Nothing
Set fldDraft = Nothing
MsgBox intCount & " messages sent - that was easy :)", vbInformation + vbOKOnly
End Sub
Upvotes: 1