Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Excel to Schedule Task in Outlook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ryguy7272 - 25 Jan 2008 14:56 GMT
I get this message:
Automation error.  The specified module could not be found.

When I run this code:
Sub CreateTask()
Dim objApp As Outlook.Application
Dim objTask As Outlook.TaskItem
     
    Set objApp = CreateObject("Outlook.Application")
    Set objTask = objApp.CreateItem(olTaskItem)
       With objTask
           .Subject = "Subject"
           .StartDate = CDate(ProximaFechaAcumulada) - CDate(15)
           .DueDate = CDate(ProximaFechaAcumulada)
           .Importance = olImportanceHigh

           .Body = "Body" 'Here    I need Right to Left
     
           .Save
          .ReminderSet = True
       End With
End Sub

It fails on this line:
Set objApp = CreateObject("Outlook.Application")

I don’t understand this behavior.  I have checked the Reference to MS
Outlook Object Library on my system and I’m having a problem with the code.  
I tried to create a small tool to simplify things in our office, but it just
doesn’t seem to work right.  When I go to a few other machines in the office
it runs fine.  I can’t tell what’s going on.  Perhaps there is some kind of
esoteric setting that is different on my workstation...  I’d appreciate it if
someone could share some insight.

Regards,
Ryan--

Signature

RyGuy

Matthew Pfluger - 25 Jan 2008 18:44 GMT
By chance do you have Outlook running when trying to run this macro?  If so,
the code will fail because only one instance of OUtlook can be open at any
time.

Instead, try this code:

Sub GetOutlookReference()

   'Outlook objects
   Dim olApp As Outlook.Application
   
   'Obtain a reference to Outlook
   On Error Resume Next
   Set olApp = GetObject(, "Outlook.Application")

   'If Outlook isn't running, start it and remember
   If olApp Is Nothing Then
       Set olApp = CreateObject("Outlook.Application")
   End If

   ' If Outlook still isn't running, Outlook cannot open or is not installed
   If olApp Is Nothing Then
       Call MsgBox("Outlook could not be opened.  Exiting macro.", _
       vbCritical, Application.Name)
   End If
       
End Sub

I cannot test this code since we do not have Outlook at work, but if you
still need help, I can test it at home.  Otherwise, here's a link to the
Outlook VBA Newsgroup:

http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.dev
eloper.outlook.vba


Matthew Pfluger

> I get this message:
> Automation error.  The specified module could not be found.
[quoted text clipped - 32 lines]
> Regards,
> Ryan--
ryguy7272 - 25 Jan 2008 21:01 GMT
Thanks for looking at this Matt!

If I open Outlook and run your coed, nothing happens.  If I close Outlook
and run your code, I get an error message:  'Outlook could not be opened.  
Exiting macro'.  I guess olApp = Nothing...

This is the code that I am trying to run now:
Sub GetOutlookReference()

'Outlook objects
Dim olApp As Outlook.Application

'Obtain a reference to Outlook
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'*********************************************
   Dim objApp As Object
   Dim OutTask As Object
   
   Set objApp = CreateObject("Outlook.Application")
   Set OutTask = objApp.CreateItem(olTaskItem)
   With OutTask

       .StartDate = Range("C1")
       .DueDate = Range("C2")
       .Importance = olImportanceHigh
       .Display
       .ReminderSet = True
   End With
'*********************************************

'If Outlook isn't running, start it and remember
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If

' If Outlook still isn't running, Outlook cannot open or is not installed
If olApp Is Nothing Then
Call MsgBox("Outlook could not be opened. Exiting macro.", _
vbCritical, Application.Name)
End If

End Sub

Basically, nothing happens when the code fires.
Not sure what to make of all this.  Got any other thoughts?

Regards,
Ryan---

Signature

RyGuy

> By chance do you have Outlook running when trying to run this macro?  If so,
> the code will fail because only one instance of OUtlook can be open at any
[quoted text clipped - 68 lines]
> > Regards,
> > Ryan--
JP - 25 Jan 2008 21:40 GMT
Try this, it is a full replacement for your code. i.e delete your
existing code and replace it with this.

Sub GetOutlookReference()

Dim olApp As Outlook.Application
Dim OutTask As Outlook.TaskItem

On Error Resume Next
   Set olApp = GetObject(, "Outlook.Application")
   If Err.Number <> 0 Then
       Set olApp = CreateObject("Outlook.Application")
   End If
On Error GoTo 0

If olApp Is Nothing Then
   MsgBox "Cannot start Outlook.", vbExclamation
   Exit Sub
End If

Set OutTask = olApp.CreateItem(olTaskItem)

With OutTask
       .StartDate = range("C1")
       .DueDate = range("C2")
       .Importance = olImportanceHigh
       .Display
       .ReminderSet = True
   End With

End Sub

HTH,
JP

On Jan 25, 4:01 pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
wrote:
> Thanks for looking at this Matt!
>
[quoted text clipped - 127 lines]
>
> - Show quoted text -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.