Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am I being clever, or asking for problems?

Status
Not open for further replies.

mintjulep

Technical User
Aug 20, 2004
1,551
JP
Code:
Public Sub MakeAppointment(usingApplication As Object, aStart As Date, aEnd As Date, aAllDay As Boolean, aBody As String, aSubject As String, aLocation As String, aBusy As Integer, aRemind As Boolean)
Dim olApp As Object
Dim olApt As Object
Set olApp = usingApplication
Set olApt = olApp.createitem(1)
With olApt
    .Start = aStart
    .End = aEnd
    .alldayevent = aAllDay
    .body = aBody
    .subject = aSubject
    .Location = aLocation
    .busystatus = aBusy
    .reminderset = aRemind
    .Save
End With

End Sub

Public Function ReadyOutlook() As Object

Dim olApp As Object

        On Error Resume Next
        Set olApp = GetObject(, "Outlook.Application") 'If Outlook is already running set existing instance as olApp
        
            'if Outlook is not running then creat an instance
            If Err.Number = 429 Then
             Set olApp = CreateObject("Outlook.Application")
            End If
             
        On Error GoTo 0
        Set olNs = olApp.GetNamespace("MAPI")
        
        'Se a aplicação não retornar nada, esta rotina criará uma e, neste caso, indica o caminho para acessar a pasta default
        'Se retornar, apenas indicará o que acessar, neste caso, a pasta default
        If olApp.ActiveExplorer Is Nothing Then
            'Por default, a pasta de acesso à aplicação é a pasta onde encontra-se MAPI
            olApp.Explorers.Add(olNs.GetDefaultFolder(9), 0).Activate
        Else
            Set olApp.ActiveExplorer.CurrentFolder = olNs.GetDefaultFolder(9)
            '9 é o número que define o default
            olApp.ActiveExplorer.Display
        End If
        
        Set ReadyOutlook = olApp
End Function

The Sub MakeAppointment simply makes an Outlook Appointment Item. Pretty straight forward. Its first argument is an Object that needs to be an Outlook Application.

The Function ReadyOutlook checks for the existence of an Outlook instance, and creates one if there isn't. Then it does some stuff to get to and show the calender. ReadyOutlook also returns an Outlook Application object.

So in use:

Code:
MakeAppointment(ReadyOutlook, arg2, arg3, arg4,....,arg8)

Seems to work just fine.

So, was I clever when I dreamed this up, or am I asking for trouble, not following good practices, angering Bill Gates.....?
 

No problems!

Outlook can only have a single instance and CreateObject will return the existing instance if it exists, and not create a second one. In theory, you are doing the right thing, but in practice it doesn't make any difference.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top