Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 23/08/2011, 14h50   #1
Membre habitué
 
Inscription : mai 2007
Messages : 314
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 314
Points : 106
Points : 106
Par défaut Nom d'utilisateur dans un TextBox

Bonjour,
je voudrais mettre en place une TextBox pour des commentaires comme une sorte de chat eg:
a chaque fois qu'un utilisateur voudrait mettre un commentaire, il sélectionne la TextBox donc le curseur doit se mettre sur la dernière ligne et insérer le nom de machine de l’utilisateur, voici a quoi le contenu du TextBox doit ressembler:

Pierre: il fait chaud
Paul: oui je confirme
jack: pas trop comme même

merci pour votre aide
LaPanic est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/08/2011, 15h25   #2
Responsable Visual Basic
 
Avatar de bbil
 
Inscription : juin 2003
Messages : 11 773
Détails du profil
Informations personnelles :
Âge : 45
Localisation : France, Ariège (Midi Pyrénées)

Informations forums :
Inscription : juin 2003
Messages : 11 773
Points : 16 849
Points : 16 849
Envoyer un message via Skype™ à bbil
et tu sais faire quoi ? intercepter l'événement de sélection de ton text box ? récupérer le nom d'utilisateur ? écrire dans ton text box ?

essai de découper ton travail en tâche élémentaires et dit nous ce que tu n'arrive pas à faire ...
bbil est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/08/2011, 15h56   #3
Membre habitué
 
Inscription : mai 2007
Messages : 314
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 314
Points : 106
Points : 106
Merci bbil,

voici le code qui me permet d'activer la Textbox:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
If CommandButton1.Caption = ("Insert Comment") Then
CommandButton1.Caption = ("Save")
 
With TextBox1
    .Locked = False
    .SetFocus
    .EnterKeyBehavior = True
    .BackColor = -2147483643
    .SpecialEffect = fmSpecialEffectSunken
    .MousePointer = fmMousePointerDefault
'    .CanPaste = True
End With
 
TextBox1.Value = ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 10 + ComboBox2.ListIndex)
Else
ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 10 + ComboBox2.ListIndex) = TextBox1.Value
CommandButton1.Caption = ("Insert Comment")
 
With TextBox1
    .BackColor = -2147483633
    .SpecialEffect = fmSpecialEffectFlat
    .Locked = True
    .MousePointer = fmMousePointerArrow
End With
 
End If
et je veux que lors de l'activation du TextBox il insère le nom de l'utilisateur si la TexteBox est vide sinon il doit insérer le nom dans la dernière ligne

je reste a votre disposition pour plus de détails
LaPanic est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/08/2011, 17h23   #4
Invité de passage
 
Homme
Inscription : août 2011
Messages : 4
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : août 2011
Messages : 4
Points : 4
Points : 4
Bonjour LaPanic

Je ne sais pas si cela va te servir mais tu pourrais utiliser cette partie de code

Code :
1
2
3
4
5
6
7
8
 
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Déclaration de la variable du pseudonyme ( a renseigner )
 
 
TextBox1.Text = TextBox1.Text & Chr(10) & Environ("USERNAME") & " : "
 
End sub
Bonne chance
Balborio
Balborio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/08/2011, 17h41   #5
Expert Confirmé Sénior
 
Avatar de jfontaine
 
Homme Jérôme FONTAINE
Contrôleur de Gestion
Inscription : juin 2006
Messages : 3 894
Détails du profil
Informations personnelles :
Nom : Homme Jérôme FONTAINE
Âge : 38
Localisation : France, Sarthe (Pays de la Loire)

Informations professionnelles :
Activité : Contrôleur de Gestion

Informations forums :
Inscription : juin 2006
Messages : 3 894
Points : 7 177
Points : 7 177
Bonjour,

Ci dessous une solution pour insérer le nom de l'utilisateur windows dans une textbox

Code :
1
2
3
Private Sub TextBox1_GotFocus()
If TextBox1.Value = "" Then TextBox1.Value = Environ("USERNAME") & Chr(13)
End Sub
__________________
Jérôme

Citation:
"Ils ne savaient pas que c'était impossible, alors ils l'ont fait" - Marc Twain
Si la réponse répond à votre besoin, votre vote nous encouragera.
Dans le cas ou la réponse mérite, à vos yeux, un , nous faire partager la raison de ce vote, pourrait nous permettre de nous améliorer.
jfontaine est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/08/2011, 12h04   #6
Membre habitué
 
Inscription : mai 2007
Messages : 314
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 314
Points : 106
Points : 106
Bonjour et merci pour vos réponses:
j'ai ajouté le code suivant et ça marche sauf que la j'essaye de perfectionner

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Dim Z, Y As String
 
If CommandButton1.Caption = ("Insert Comment") Then
CommandButton1.Caption = ("Save")
Z = ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 10 + ComboBox2.ListIndex)
With TextBox1
    .Locked = False
    .SetFocus
    .EnterKeyBehavior = True
End With
 
    TextBox1.Value = Z
    If TextBox1.Value = "" Then
    TextBox1.Value = Environ("USERNAME") & ": " & Y
    Else
    TextBox1.Value = Z & Chr(10) & Chr(10) & Environ("USERNAME") & ": " & Y
    End If
 
Else
ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 10 + ComboBox2.ListIndex) = TextBox1.Value
CommandButton1.Caption = ("Insert Comment")
 
With TextBox1
    .Locked = True
End With
 
End If
j'ai ajouté une variable Y pour récupérer le texte saisi par l'utilisateur car si celui ci saisie un texte donc il peut sauvegarder son nom et le texte saisi sinon (ne saisi aucun texte ) il sauvegarde le texte initial dans la TextBox
je me suis un peut embrouillé et merci pour votre aide
LaPanic est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/08/2011, 17h20   #7
Membre habitué
 
Inscription : mai 2007
Messages : 314
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 314
Points : 106
Points : 106
Bonjour,
j'ai trouvé une solution qui marche bien sauf que si c'est possible d'optimiser !?
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Private Sub CommandButton1_Click()
Dim Z, Y, W As String
 
Y = Environ("username") & ": "
If CommandButton1.Caption = ("Insert Comment") Then
    CommandButton1.Caption = ("Save")
    Z = ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 15 + ComboBox2.ListIndex)
    With TextBox1
        .Locked = False
        .SetFocus
        .EnterKeyBehavior = True
    End With
 
        If Len(Z) - Len(Y) > 0 Then
            W = Z & Chr(10) & Chr(10) & Y
        Else
            W = Y
        End If
        TextBox1.Value = W
Else
 
        If Len(TextBox1.Value) - Len(Y) > 0 Then
 
            If Right(TextBox1.Value, Len(Y)) = Y Then
                TextBox1.Value = ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 15 + ComboBox2.ListIndex)
            End If
 
        Else
            TextBox1.Value = ""
        End If
 
    ThisWorkbook.Worksheets("Dashboard").Range("B" & BB).Offset(0, 15 + ComboBox2.ListIndex) = TextBox1.Value
    CommandButton1.Caption = ("Insert Comment")
 
    With TextBox1
        .Locked = True
    End With
 
End If
End Sub
merci pour votre aide
LaPanic est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 16h40.


 
 
 
 
Partenaires

Hébergement Web