Running macro in two linked worksheets

Goody61865

Board Regular
Joined
Mar 4, 2011
Messages
50
I put a due date on one worksheet without the outlook code and it goes to another worksheet with the outlook code. This code populates the outlook calender with the event. My problem is that the code runs great both automatically and manually but it only fills the calender event when ran manually. Why wont it populate the calender in auto when the code runs?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I wasnt sure where to put the "DoEvents"

Here is my code:

Sub Update_Calender(FormulaCell As Range)

Dim objOL As Object
Dim objItem As Object
Dim lngRow As Long

Set objOL = CreateObject("Outlook.Application")

lngRow = 4

If ActiveSheet.Cells(lngRow, 2).Text <> "" Then
Set objItem = objOL.createitem(1) ' constant olAppointmentItem = 1

With objItem
.Body = Cells(FormulaCell.Row, "B").Value & vbNewLine & vbNewLine & _
"Your task is due : " & Cells(FormulaCell.Row, "A").Value & _
vbNewLine & vbNewLine & "Please update your task"
.Duration = 60
.Start = Cells(FormulaCell.Row, "D").Value & " 9:00:00 AM"
.Subject = Range("B4").Value
.ReminderMinutesBeforeStart = "30"
.Save

End With
End If
lngRow = lngRow + 1

Set objItem = Nothing
Set objOL = Nothing
MsgBox "Your due date for this task has been added to your calender"
End Sub
 
Upvote 0
I'm not sure it will help but I'd put it between the "End With" and "End If".

Maybe the .Save is still in progress when it gets to the MsgBox. DoEvents should force it to do its housekeeping before it displays that modal message box.

Gary
 
Upvote 0
No luck, thanks though

For some reason it is not recognizing "If Activesheet.Cells blah blah.Value" when running automatic. It runs through just fine manually.
 
Upvote 0
Another guess:

Maybe "CreateObject" shifts the focus to Outlook. Therefore you don't have an active sheet (or workbook for that matter)?

How about "AppActivate" to set the focus back to Excel.

Gary
 
Upvote 0
Do I replace it? or set another object? I tried both and it still isnt going. I dont understand because manually it runs just fine.
 
Upvote 0
Forgive me, I am relatively new to this. How do I set the focus back using the AppActivate? Every time I try adding it I get an error argument not optional.
 
Upvote 0
Try something like this:

Code:
Dim sCaption As String

sCaption = ThisWorkbook.Application.Caption

'Start Outlook here ... Createobject

AppActivate sCaption 'Set focus back to Excel
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,172
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top