Besoin d'aide

Lone-wolf

XLDnaute Barbatruc
Bonjour à tous,

depuis ce matin j'aissaie et ressaie encore, de modifier le code que voici.

Soit il supprime les deux dernières lignes où sont inscrit les contacts,
soit il supprime qu'à moitié le contact choisi. Tous ça dans la feuille Excel.

En plus, je n'arrive pas à supprimer le contact dans Outlook.

Il ne me reste plus que ce code pour terminer le formulaire, si l'un d'entre vous veux bien m'aider.

Voici le code:

Code:
Private Sub Supprimer_Click()
    Dim Line As String
    Line = UserForm1.TextBox12.Value
    For i = 1 To 10
    Sheets(1).Cells(Line, i).Value = UserForm1.Controls("textbox" & i).Value
    ActiveCell.EntireRow.Delete 
    UserForm1.Controls("textbox" & i).Value = ""
    Next
    UserForm1.TextBox11.Value = ""
    UserForm1.TextBox12.Value = ""
    TextBox1.SetFocus
    'Suppression du contact dans Outlook
  Dim objOutlook As Outlook.Application
  Dim objContact As Outlook.ContactItem
  Dim olApp As New Outlook.Application
  Dim Contact As ContactItem
  Dim dossierContacts As Outlook.MAPIFolder
  
  Set olApp = New Outlook.Application
  Set dossierContacts = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
  Set Contact = dossierContacts.Items.Find _
  ("[FullName] = '" & UserForm1.TextBox2.Value & "'")
On Error Resume Next
Contact.Delete
End Sub

Fichier à télécharger
 

soenda

XLDnaute Accro
Re : Besoin d'aide

Bonjour le fil, lonewolf

J'ai du mal pour comprendre ton code.

Exemple 1:
Code:
For i = 1 To 10
    [COLOR=red]Sheets(1).Cells(Line, i).Value = UserForm1.Controls("textbox" & i).Value[/COLOR]
    [COLOR=red]ActiveCell.EntireRow.Delete[/COLOR] 
    . . .
Next
Tu écris une info dans une cellule et tout de suite après,
tu supprimes la ligne entière (et donc l'info) :confused:


Exemple 2:
Code:
Next
    UserForm1.TextBox11.Value = ""
    [COLOR=red]UserForm1.TextBox12.Value = ""[/COLOR]
    . . .
  Set Contact = dossierContacts.Items.Find _
  ("[FullName] = '" &[COLOR=red] UserForm1.TextBox2.Value[/COLOR] & "'")
Tu cherches une info dans le dossier contact,
info que tu as supprimé avant d'effectuer la recherche :confused:

A plus
 

Lone-wolf

XLDnaute Barbatruc
Re : Besoin d'aide

Bonjour Soenda,

J'ai une textbox et un bouton de recherche déjà.

Suite à la recherche, le bouton supprimer sert à:

Supprimer le contact dans la liste Outlook
Supprimer le contact dans la feuille
Les lignes avec UserForm1. = "" servant à vider les texbox du formulaire.

Je remet le code fonctionnel:

Code:
Private Sub Supprimer_Click()
 Dim olApp As Outlook.Application
    Dim dossierContacts As Outlook.MAPIFolder
    Dim Contact As Outlook.ContactItem
    Set olApp = New Outlook.Application
    Set dossierContacts = olApp.GetNamespace("MAPI"). _
        GetDefaultFolder(olFolderContacts)
    Set Contact = dossierContacts.Items.Find _
        ("[FullName] = '" & UserForm1.TextBox2 & "'")
If Not Contact Is Nothing Then
Contact.Delete
End If
TextBox1.SetFocus
    Dim Line As String
    Dim derligne As String
    Dim i As Long
    derligne = Range("a65536").End(xlUp).Row
    Line = UserForm1.TextBox12.Value
    For i = 1 To 10
    Sheets(1).Cells(Line, i).Value = UserForm1.Controls("textbox" & i).Value
    Sheets(1).Cells(Line, i).Delete
    UserForm1.Controls("textbox" & i).Value = ""
    Next
If Cells(derligne + 1, 1).Value = "" Then
Cells(derligne, 1).EntireRow.Delete
End If
    UserForm1.TextBox11.Value = ""
    UserForm1.TextBox12.Value = ""
    TextBox1.SetFocus
End Sub

Maintenant j'ai un autre problème à résoudre.
Tu vas me dire c'est bête comme tout et pourtant...
j'ai chercher un code sur le forum, sans succès.

J'ai un autre formulaire fait un peu différemment et j'aimerais obtenir
le même résultat.

Code:
Private Sub Supprimer_Click()
Dim olApp As Outlook.Application
    Dim dossierContacts As Outlook.MAPIFolder
    Dim Contact As Outlook.ContactItem
    
    Set olApp = New Outlook.Application
    Set dossierContacts = olApp.GetNamespace("MAPI"). _
        GetDefaultFolder(olFolderContacts)
    Set Contact = dossierContacts.Items.Find _
        ("[FullName] = '" & Prénom.Value & " " & Nom.Value & "'")
        
   If Not Contact Is Nothing Then
       Contact.Delete
    End If
   Nom.SetFocus
 
[SIZE="2"][COLOR="Red"]'  Ici le code à introduire pour supprimer le contact dans la feuille Excel.
Nom de la feuille Liste - Nb de Colonnes 9[/COLOR][/SIZE]



'Liberer les TexBox
Nom.Value = ""
Prénom.Value = ""
Adresse.Value = ""
CP.Value = ""
Ville.Value = ""
Téléphone.Value = ""
Mobile.Value = ""
Email.Value = ""
Web.Value = ""
Rechercher.Value = ""
Rechercher.SetFocus
End Sub

Dans tous les cas, merci d'avoir répondu.
 

Discussions similaires

Statistiques des forums

Discussions
312 379
Messages
2 087 764
Membres
103 661
dernier inscrit
fcleves