OVH Cloud OVH Cloud

Exporter la tache ouverte dans Excel

2 réponses
Avatar
Cath
Bonjour à tous,

Suite aux différents messages pour trouver le code Exportation Tache dans
Excel se Sue Mtoher.

J'ai enfin pu le télécharger sur un site outlook.com

J'ai réussi à adapter ce code à mon besoin. Le petit souci est que ce code
exporte toutes les tâches terminées alors que je veux uniquement la tâche qui
est à l'écran.

Voici mon code, pourriez-vous m'aider à le modifier. Merci
Sub TaskExcel()

Dim ol As Outlook.Application
Dim objExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim rng As Excel.Range
Dim ns As NameSpace
Dim Tsk As TaskItem

Dim Cherche As String
Dim LaPlage As Range, Cell As Range, FirstCell As Range

Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")

For Each Tsk In ns.GetDefaultFolder(olFolderTasks).Items

If Tsk.Complete = True Then

Set objExcel = CreateObject("excel.application")
Set wkb = objExcel.Workbooks.Open("c:\toto.xls")
wkb.Activate
objExcel.Application.Visible = True

Set wks = wkb.Worksheets(1)

With Worksheets(Format(Tsk.DueDate, "mmmm"))
MsgBox Tsk.DueDate
MsgBox Format(Tsk.DueDate, "mmmm")

Set LaPlage = .Range("B3:D200")
End With

Cherche = Tsk.DueDate 'L'expression à trouver

Set FirstCell = LaPlage. _
Find(what:=Cherche, after:=ActiveCell, LookIn:=xlValues,
Lookat:=xlWhole, SearchOrder:=xlByRows)
Set Cell = FirstCell

Do
If Not FirstCell Is Nothing Then
MsgBox FirstCell.Address
FirstCell(15) = Now()
'Exit Do 'Si veux arrêter après le premier élément trouvé.
Else
MsgBox "Aucune Tâche ne correspond"
Exit Do
End If

Loop While Not Cell Is Nothing And Cell.Address <> FirstCell.Address

Set LaPlage = Nothing: Set FirstCell = Nothing: Set Cell = Nothing
End If

Next Tsk

Set Tsk = Nothing : Set ns = Nothing :Set ol = Nothing

End Sub

2 réponses

Avatar
Oliv'
Bonjour à tous,

Suite aux différents messages pour trouver le code Exportation Tache
dans Excel se Sue Mtoher.

J'ai enfin pu le télécharger sur un site outlook.com

J'ai réussi à adapter ce code à mon besoin. Le petit souci est que ce
code exporte toutes les tâches terminées alors que je veux uniquement
la tâche qui est à l'écran.

Voici mon code, pourriez-vous m'aider à le modifier. Merci


J'y ai fait quelques modifications,
mais que doit faire ta macro ? exporter la tache ou mettre à jour la tache
dans le fichier excel ?

Sub TaskExcel()

Dim ol As Outlook.Application
Dim objExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim rng As Excel.Range
Dim ns As NameSpace
Dim Tsk As TaskItem

Dim Cherche As String
Dim LaPlage As Range, Cell As Range, FirstCell As Range

Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")

Set Tsk = ActiveInspector.CurrentItem

If Tsk.Complete = True Then

Set objExcel = CreateObject("excel.application")
Set wkb = objExcel.Workbooks.Open("c:toto.xls")
wkb.Activate
objExcel.Application.Visible = True

Set wks = wkb.Worksheets(1)

With wkb.Worksheets(Format(Tsk.DueDate, "mmmm"))
MsgBox Tsk.DueDate
MsgBox Format(Tsk.DueDate, "mmmm")

Set LaPlage = .Range("B3:D200")
End With

Cherche = Tsk.DueDate 'L'expression à trouver

Set FirstCell = LaPlage. _
Find(what:=Cherche, After:¬tiveCell, LookIn:=xlValues,
Lookat:=xlWhole, SearchOrder:=xlByRows)
Set Cell = FirstCell

Do
If Not FirstCell Is Nothing Then
MsgBox FirstCell.Address
FirstCell(15) = Now()
'Exit Do 'Si veux arrêter après le premier élément trouvé.
Else
MsgBox "Aucune Tâche ne correspond"
Exit Do
End If

Loop While Not Cell Is Nothing And Cell.Address < FirstCell.Address

Set LaPlage = Nothing: Set FirstCell = Nothing: Set Cell = Nothing
End If


Set Tsk = Nothing: Set ns = Nothing: Set ol = Nothing

End Sub




--
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Have a nice day
Oliv'
Pour me joindre : http://cerbermail.com/?V8r2o1YHl4
les sites références:
Excel :http://www.excelabo.net http://xcell05.free.fr/
http://dj.joss.free.fr/
http://frederic.sigonneau.free.fr/ http://www.excel-vba-francais.com/
Word : http://faqword.free.fr/
Outlook :http://faq.outlook.free.fr/
Sql :http://sqlpro.developpez.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Avatar
Cath
Merci pour cette réponse.

Effectivement je dois mettre à jour la tache dans le fichier Excel.

Je vais tester.



Bonjour à tous,

Suite aux différents messages pour trouver le code Exportation Tache
dans Excel se Sue Mtoher.

J'ai enfin pu le télécharger sur un site outlook.com

J'ai réussi à adapter ce code à mon besoin. Le petit souci est que ce
code exporte toutes les tâches terminées alors que je veux uniquement
la tâche qui est à l'écran.

Voici mon code, pourriez-vous m'aider à le modifier. Merci


J'y ai fait quelques modifications,
mais que doit faire ta macro ? exporter la tache ou mettre à jour la tache
dans le fichier excel ?

Sub TaskExcel()

Dim ol As Outlook.Application
Dim objExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim rng As Excel.Range
Dim ns As NameSpace
Dim Tsk As TaskItem

Dim Cherche As String
Dim LaPlage As Range, Cell As Range, FirstCell As Range

Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")

Set Tsk = ActiveInspector.CurrentItem

If Tsk.Complete = True Then

Set objExcel = CreateObject("excel.application")
Set wkb = objExcel.Workbooks.Open("c:toto.xls")
wkb.Activate
objExcel.Application.Visible = True

Set wks = wkb.Worksheets(1)

With wkb.Worksheets(Format(Tsk.DueDate, "mmmm"))
MsgBox Tsk.DueDate
MsgBox Format(Tsk.DueDate, "mmmm")

Set LaPlage = .Range("B3:D200")
End With

Cherche = Tsk.DueDate 'L'expression à trouver

Set FirstCell = LaPlage. _
Find(what:=Cherche, After:¬tiveCell, LookIn:=xlValues,
Lookat:=xlWhole, SearchOrder:=xlByRows)
Set Cell = FirstCell

Do
If Not FirstCell Is Nothing Then
MsgBox FirstCell.Address
FirstCell(15) = Now()
'Exit Do 'Si veux arrêter après le premier élément trouvé.
Else
MsgBox "Aucune Tâche ne correspond"
Exit Do
End If

Loop While Not Cell Is Nothing And Cell.Address < FirstCell.Address

Set LaPlage = Nothing: Set FirstCell = Nothing: Set Cell = Nothing
End If


Set Tsk = Nothing: Set ns = Nothing: Set ol = Nothing

End Sub




--
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Have a nice day
Oliv'
Pour me joindre : http://cerbermail.com/?V8r2o1YHl4
les sites références:
Excel :http://www.excelabo.net http://xcell05.free.fr/
http://dj.joss.free.fr/
http://frederic.sigonneau.free.fr/ http://www.excel-vba-francais.com/
Word : http://faqword.free.fr/
Outlook :http://faq.outlook.free.fr/
Sql :http://sqlpro.developpez.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~