Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Erreur suite exécution Set objSession = CreateObject("MAPI.Session")

2 réponses
Avatar
boubi
Bonjour

Je vous contacte car je rencontre un petit problème avec un scripts en vbs
qui récupère dans le carnet d'adresse Outlook via CDO des informations.

Le scripts fonctionne correctement, les informations sont bien récupéré ,
mais le problème est que ensuite l'appel à des autres fonctions ne fonction
plus :

Exemple :

function outlook()

Const cdoE_USER_CANCEL = &H80040113

' start CDO session

Set objSession = CreateObject("MAPI.Session")


objSession.Logon , , False, False
On Error Resume Next
'' Set myGAddressList = oSession.AddressLists("Global Address List")
Set colCDORecips = objSession.AddressBook(, _
"Sélectionner un Nom", , , 1, _
"La personne")
If Err = 0 Then
If colCDORecips.Count <> 1 Then
MsgBox "Merci de définir une personne uniquement.", , _
"Chose One Name"
Else
'strName = colCDORecips.Item(1).AddressEntry.Name
strNom =
colCDORecips.Item(1).AddressEntry.Fields(CdoPR_SURNAME).Value
strPrenom =
colCDORecips.Item(1).AddressEntry.Fields(CdoPR_GIVEN_NAME).Value
strBureau =
colCDORecips.Item(1).AddressEntry.Fields(CdoPR_OFFICE_LOCATION).Value
strService =
colCDORecips.Item(1).AddressEntry.Fields(CdoPR_DEPARTMENT_NAME).Value
'strName = colCDORecips.Fields(CdoPR_SURNAME).Value
'msgbox strService

If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot return " & _
"a name, because " & _
"you clicked No on the " & _
"e-mail address access " & _
"dialog. You need to try " & _
"again and click Yes " & _
"this time.", , _
"E-mail Address Access"
End If
End If
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If

GetOneNameViaCDO = strName

' release objects
objSession.Logoff
'colCDORecips.Logoff
Set colCDORecips = Nothing
Set objSession = Nothing

Document.info.nom.value=strNom
Document.info.prenom.value=strPrenom
Document.info.bureau.value=strBureau
Document.info.section.value=strService
end function

Ensuite l'appel à la fonction :

retourcode=objShell.Run ("Scripts\inventaire\inv.cmd ",1,true)

ne fonctionne plus, l'erreur indique à l'execution " fichier spécifié est
introuvable"

Pourtant avant appel à l'objet " Set objSession =
CreateObject("MAPI.Session") " cela fonctionne très bien

Je cherche, mais je trouve pas, si quelqu'un à une idée je suis preneur

Cordialement

2 réponses

Avatar
Michel__D
Bonjour,

boubi a écrit :
Bonjour

Je vous contacte car je rencontre un petit problème avec un scripts en vbs
qui récupère dans le carnet d'adresse Outlook via CDO des informations.

Le scripts fonctionne correctement, les informations sont bien récupéré ,
mais le problème est que ensuite l'appel à des autres fonctions ne fonction
plus :

Exemple :

function outlook()

Const cdoE_USER_CANCEL = &H80040113

' start CDO session

Set objSession = CreateObject("MAPI.Session")


objSession.Logon , , False, False
On Error Resume Next
'' Set myGAddressList = oSession.AddressLists("Global Address List")
Set colCDORecips = objSession.AddressBook(, _
"Sélectionner un Nom", , , 1, _
"La personne")
If Err = 0 Then
If colCDORecips.Count <> 1 Then
MsgBox "Merci de définir une personne uniquement.", , _
"Chose One Name"
Else
'strName = colCDORecips.Item(1).AddressEntry.Name
strNom > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_SURNAME).Value
strPrenom > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_GIVEN_NAME).Value
strBureau > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_OFFICE_LOCATION).Value
strService > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_DEPARTMENT_NAME).Value
'strName = colCDORecips.Fields(CdoPR_SURNAME).Value
'msgbox strService

If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot return " & _
"a name, because " & _
"you clicked No on the " & _
"e-mail address access " & _
"dialog. You need to try " & _
"again and click Yes " & _
"this time.", , _
"E-mail Address Access"
End If
End If
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If

GetOneNameViaCDO = strName

' release objects
objSession.Logoff
'colCDORecips.Logoff
Set colCDORecips = Nothing
Set objSession = Nothing

Document.info.nom.value=strNom
Document.info.prenom.value=strPrenom
Document.info.bureau.value=strBureau
Document.info.section.value=strService
end function

Ensuite l'appel à la fonction :

retourcode=objShell.Run ("Scriptsinventaireinv.cmd ",1,true)

ne fonctionne plus, l'erreur indique à l'execution " fichier spécifié est
introuvable"

Pourtant avant appel à l'objet " Set objSession > CreateObject("MAPI.Session") " cela fonctionne très bien

Je cherche, mais je trouve pas, si quelqu'un à une idée je suis preneur

Cordialement



Hum pas clair ton énoncé :

1) La fonction outlook() est située dans quel fichier ?

2) Le code suivant est situé dans quel fichier ?
retourcode=objShell.Run ("Scriptsinventaireinv.cmd ",1,true)

3) Donne le chemin complet en paramêtre, par exemple :
retourcode=objShell.Run ("c:Scriptsinventaireinv.cmd",1,true)

Bien entendu il faut avoir déclarer la variable objet "objShell"
et que le fichier existe.
Avatar
boubi
Bonjour

J'ai trouvé le problème suite à l'appel de "Set objSession =
CreateObject("MAPI.Session")"

le chemin par défaut de l'application change.

Avant appel :

c:Program Files ApplisScripts

Après appel

c:Program Files Fiches communsSYSTEMMSMAPI1036

Donc j'ai sauvegarde le chemin avant et réaffecter le chemin après appel :

Set objShell2=CreateObject("WScript.Shell")
sauvepath=objShell2.CurrentDirectory

Puis après appel de la fonction outlook

objShell2.CurrentDirectory=sauvepath

Voila merci de votre aide.

"boubi" a écrit dans le message de news:
4a7dda59$0$25125$
Bonjour

Je vous contacte car je rencontre un petit problème avec un scripts en vbs
qui récupère dans le carnet d'adresse Outlook via CDO des informations.

Le scripts fonctionne correctement, les informations sont bien récupéré ,
mais le problème est que ensuite l'appel à des autres fonctions ne
fonction
plus :

Exemple :

function outlook()

Const cdoE_USER_CANCEL = &H80040113

' start CDO session

Set objSession = CreateObject("MAPI.Session")


objSession.Logon , , False, False
On Error Resume Next
'' Set myGAddressList = oSession.AddressLists("Global Address List")
Set colCDORecips = objSession.AddressBook(, _
"Sélectionner un Nom", , , 1, _
"La personne")
If Err = 0 Then
If colCDORecips.Count <> 1 Then
MsgBox "Merci de définir une personne uniquement.", , _
"Chose One Name"
Else
'strName = colCDORecips.Item(1).AddressEntry.Name
strNom > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_SURNAME).Value
strPrenom > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_GIVEN_NAME).Value
strBureau > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_OFFICE_LOCATION).Value
strService > colCDORecips.Item(1).AddressEntry.Fields(CdoPR_DEPARTMENT_NAME).Value
'strName = colCDORecips.Fields(CdoPR_SURNAME).Value
'msgbox strService

If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot return " & _
"a name, because " & _
"you clicked No on the " & _
"e-mail address access " & _
"dialog. You need to try " & _
"again and click Yes " & _
"this time.", , _
"E-mail Address Access"
End If
End If
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If

GetOneNameViaCDO = strName

' release objects
objSession.Logoff
'colCDORecips.Logoff
Set colCDORecips = Nothing
Set objSession = Nothing

Document.info.nom.value=strNom
Document.info.prenom.value=strPrenom
Document.info.bureau.value=strBureau
Document.info.section.value=strService
end function

Ensuite l'appel à la fonction :

retourcode=objShell.Run ("Scriptsinventaireinv.cmd ",1,true)

ne fonctionne plus, l'erreur indique à l'execution " fichier spécifié est
introuvable"

Pourtant avant appel à l'objet " Set objSession > CreateObject("MAPI.Session") " cela fonctionne très bien

Je cherche, mais je trouve pas, si quelqu'un à une idée je suis preneur

Cordialement