jackson1990
Board Regular
- Joined
- Feb 21, 2017
- Messages
- 56
Everyone has been so helpful on here, so thanks so far for that!
So, I have some code to cause an outlook appointment to be populated with information from cell A2 and E14. Which works as designed, but I want to use this single macro multiple times on the same sheet. For example there is going to be 10 buttons all going down the sheet, A2 and E14 coordinate with the first block of information then it will be A15 and E26, then A27 and E38 and so on. Ideally I'd like for it to be dynamic somehow so it could search the title in a2 then a15 then a27. But I'm kind of having a block of how I would go about that? The reason behind this is so when I hand the project off to someone else who may not know VBA they are able to change the structure of the sheet without breaking the macro. If I simply make 10 buttons if they were to change where the title was from a2 to b2 then it would be broken and they'd be confused. Is there anyway I can accomplish this or is this impossible? I provided code below.
So, I have some code to cause an outlook appointment to be populated with information from cell A2 and E14. Which works as designed, but I want to use this single macro multiple times on the same sheet. For example there is going to be 10 buttons all going down the sheet, A2 and E14 coordinate with the first block of information then it will be A15 and E26, then A27 and E38 and so on. Ideally I'd like for it to be dynamic somehow so it could search the title in a2 then a15 then a27. But I'm kind of having a block of how I would go about that? The reason behind this is so when I hand the project off to someone else who may not know VBA they are able to change the structure of the sheet without breaking the macro. If I simply make 10 buttons if they were to change where the title was from a2 to b2 then it would be broken and they'd be confused. Is there anyway I can accomplish this or is this impossible? I provided code below.
Code:
Sub EmailProp()
Dim oApp As Outlook.Application
Dim oNameSpace As Namespace
Dim oItem As AppointmentItem
On Error Resume Next
' check if Outlook is running
Set oApp = GetObject("Outlook.Application")
If Err <> 0 Then
'if not running, start it
Set oApp = CreateObject("Outlook.Application")
End If
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oItem = oApp.CreateItem(olAppointmentItem)
With oItem
.Subject = Range("A2") + " Due"
.Start = Range("E14")
.Duration = "01:00"
.AllDayEvent = True
.Importance = olImportanceNormal
.ReminderSet = True
.ReminderMinutesBeforeStart = "10"
Select Case 1 ' do you want to display the entry first or save it immediately?
Case 1
.Display
Case 2
.Save
End Select
End With
Set oApp = Nothing
Set oNameSpace = Nothing
Set oItem = Nothing
End Sub