Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2013, 04:22 AM
vodkasoda vodkasoda is offline How to update an Outlook Task in Word 2007 VBA Windows Vista How to update an Outlook Task in Word 2007 VBA Office 2007
Novice
How to update an Outlook Task in Word 2007 VBA
 
Join Date: Apr 2013
Location: Stowmarket, Suffolk, UK
Posts: 15
vodkasoda is on a distinguished road
Unhappy How to update an Outlook Task in Word 2007 VBA

I actually had all of this working a few weeks ago, but managed to lose three of my Macros when I "upgraded" from WinXP to Vista !!!



I have rewritten most code and it all seems to be working, except for this bit, I can't for the life of me remember how I updated my Outlook Tasks in my Word Macro !!!

I am linked to Outlook & am able to send an E:Mail, but I then need to update a Task and can't get it working, can anybody please tell me what I need to do here ?!?

Basically, I know *exactly* what the Task will be called, I just need to open it, edit it, save it, close it ... but at the moment I can't even link to it

Code:
Sub myButtonMacro3(control As IRibbonControl)

    myDocName = Left(ActiveDocument.Name, (InStr(ActiveDocument.Name, ".doc")) - 1)
    mySession = ""
    
    While IsNumeric(Right(myDocName, 1))
        mySession = Right(myDocName, 1) + mySession
        myDocName = Left(myDocName, Len(myDocName) - 1)
    Wend
    
    myLeagueName = Left(myDocName, Len(myDocName) - 4)
    mySubject = "NewsLetter For " + myLeagueName + " Session " + mySession
    myBody = "Here you go ..."
    
     ActiveDocument.Save
    
    Set oOutlookApp = GetObject(, "Outlook.Application")

    If Err <> 0 Then
        Set oOutlookApp = CreateObject("Outlook.Application")
        bStarted = True
    End If

    Set oItem = oOutlookApp.CreateItem(olMailItem)

    With oItem
        .To = "xxx@gmail.com"
        .Subject = mySubject
        .Body = myBody
        .Attachments.Add ActiveDocument.FullName
        .Send
    End With

    If bStarted Then
        oOutlookApp.Quit
    End If
    
    UpdateCalendar '<<< Call Routine to update Task 
    
    Set oItem = Nothing
    Set oOutlookApp = Nothing

    Application.Quit


End Sub

Sub UpdateCalendar()

'The following code is NOT working code, it is just typed up from memory, but no matter what I try,
'I cannot even get the next line working & I am getting no help from the IntelliSense system !

    Set oTsk = Outlook.TaskItem
    
    For Each oTsk In oOutlookApp
        If Task.Name = myLeagueName & " Newsletter" Then
            Task.Status = olWaitingOnSomeoneElse
            Task.Complete = "75%"
            Task.Categories = "Newsletters : Sent"
            Task.Save
        End If
    Next olTsk

End Sub
Reply With Quote
  #2  
Old 04-12-2013, 05:52 AM
macropod's Avatar
macropod macropod is offline How to update an Outlook Task in Word 2007 VBA Windows 7 64bit How to update an Outlook Task in Word 2007 VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

With your 'UpdateCalendar' sub, you have some variable naming inconsistences that should be immediately apparent - especially if you set 'Option Explicity' at the top of your code module.

The other issues you'll have with running your 'UpdateCalendar' sub are: (a) you Quit Outlook before calling it; and (b) The sub has no Outlook objects of its own.

Although I'm no Outlook expert (I don't even use it, so I don't know the object model), you might try something based on:
Code:
Sub myButtonMacro3(control As IRibbonControl)
    Dim myDocName As String, mySession As String, myLeagueName As String
    Dim mySubject As String, myBody As String
    Dim objOutlook As Object, oItem As Object, olTsk As Object
    myDocName = ActiveDocument.Name
    myDocName = Left(myDocName, (InStrRev(myDocName, ".")) - 1)
    mySession = ""
    While IsNumeric(Right(myDocName, 1))
        mySession = Right(myDocName, 1) + mySession
        myDocName = Left(myDocName, Len(myDocName) - 1)
    Wend
    myLeagueName = Left(myDocName, Len(myDocName) - 4)
    mySubject = "NewsLetter For " + myLeagueName + " Session " + mySession
    myBody = "Here you go ..."
    ActiveDocument.Save
    'Start/Run Outlook.
    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        Set oOutlookApp = CreateObject("Outlook.Application")
        bStarted = True
    End If
    'Sen Email.
    Set oItem = oOutlookApp.CreateItem(olMailItem)
    With oItem
        .To = "xxx@gmail.com"
        .Subject = mySubject
        .Body = myBody
        .Attachments.Add ActiveDocument.FullName
        .Send
    End With
    'Update Calendar.
    Set olTsk = objOutlook.TaskItem
    For Each olTsk In objOutlook
        With olTsk
            If .Name = myLeagueName & " Newsletter" Then
                .Status = olWaitingOnSomeoneElse
                .Complete = "75%"
                .Categories = "Newsletters : Sent"
                .Save
            End If
        End With
    Next olTsk
    'Quit Outlook if we started it.
    If bStarted Then oOutlookApp.Quit
    Set oItem = Nothing: Set olTsk = Nothing: Set oOutlookApp = Nothing
    Application.Quit
End Sub
As for Intellisense, your code uses late binding. If you set a reference to Outlook, you can develop your code with early binding and thus have Intellisense access. You can always revert to late binding when you're done.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-12-2013, 07:14 AM
vodkasoda vodkasoda is offline How to update an Outlook Task in Word 2007 VBA Windows Vista How to update an Outlook Task in Word 2007 VBA Office 2007
Novice
How to update an Outlook Task in Word 2007 VBA
 
Join Date: Apr 2013
Location: Stowmarket, Suffolk, UK
Posts: 15
vodkasoda is on a distinguished road
Default

Paul, thank you ... especially for pointing out "(a) you Quit Outlook before calling it" ... I feel a bit of a fool now !!! I just didn't see that line, a clear case of not seeing the wood for the trees, I guess !!!

I will take a look at what you say & see if I can get working, thanks again, I may be back later !!!
Reply With Quote
Reply

Tags
outlook 2007, word 2007, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 to Outlook 2007 - task import possible? mjwillyone Outlook 2 07-05-2023 07:23 AM
Auto update footer in Word 2007 worduser1970 Word 4 11-27-2012 08:02 AM
Outlook 2007 Task Bar marstantrails Outlook 1 05-04-2012 08:15 PM
How to update an Outlook Task in Word 2007 VBA Outlook 2007 & To-Do Task Bar Tex Outlook 1 05-18-2011 12:15 PM
Update from 2003 outlook to 2007 Cannot sort contacts alphabetically mestisoz Outlook 11 02-21-2011 02:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft