OVH Cloud OVH Cloud

VBA. SetFocus ne fonctionne pas...

4 réponses
Avatar
HD
Bonjour,

Dans mon UserForm je fais une action où le focus doit être positionné sur un
TextBox... Mais le problème est que ma commande TextBox1.SetFocus n'est pas
prise en compte...

Que se passe-t-il ?

Merci d'avance pour votre aide.
--
@+
HD

4 réponses

Avatar
Michel Gaboly
Bonjour,

SetFocus est parfois capricieux avec certaines versions d'Excel et/ou d'OS.

Indique un extrait de ton code.


Bonjour,

Dans mon UserForm je fais une action où le focus doit être positionné sur un
TextBox... Mais le problème est que ma commande TextBox1.SetFocus n'est pas
prise en compte...

Que se passe-t-il ?

Merci d'avance pour votre aide.



--
Cordialement,

Michel Gaboly
www.gaboly.com

Avatar
HD
SetFocus est parfois capricieux avec
certaines versions d'Excel et/ou d'OS.
J'ai Excel 97 SR-2 avec Windows 98.


Indique un extrait de ton code.


Voila :

Private Sub TextBox1_Change()
Dim i As Integer
Dim c As Range
Dim rep As Integer

TextBox1.SetFocus
If TextBox1.Text = "" Then Exit Sub

With Worksheets("Synth").Columns(1)
Set c = .Find(TextBox1.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
c.Select
TextBox2.Text = c.Value
End If
End With
If c Is Nothing Then
Range("A2").Select
TextBox2.Text = "*** Référence non trouvée ***"
TextBox2.ForeColor = RGB(255, 0, 0)
TextBox2.Font.Bold = True
TextBox2.TextAlign = fmTextAlignCenter
Else
TextBox2.ForeColor = RGB(0, 0, 0)
TextBox2.Font.Bold = False
TextBox2.TextAlign = fmTextAlignLeft
End If
End Sub
--
@+
HD

Avatar
HD
SetFocus est parfois capricieux avec
certaines versions d'Excel et/ou d'OS.
J'ai Excel 97 SR-2 avec Windows 98.


Indique un extrait de ton code.


Voila :

Private Sub TextBox1_Change()
Dim i As Integer
Dim c As Range
Dim rep As Integer

TextBox1.SetFocus
If TextBox1.Text = "" Then Exit Sub

With Worksheets("Synth").Columns(1)
Set c = .Find(TextBox1.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
c.Select
TextBox2.Text = c.Value
End If
End With
If c Is Nothing Then
Range("A2").Select
TextBox2.Text = "*** Référence non trouvée ***"
TextBox2.ForeColor = RGB(255, 0, 0)
TextBox2.Font.Bold = True
TextBox2.TextAlign = fmTextAlignCenter
Else
TextBox2.ForeColor = RGB(0, 0, 0)
TextBox2.Font.Bold = False
TextBox2.TextAlign = fmTextAlignLeft
End If
End Sub
--
@+
HD

Avatar
HD
SetFocus est parfois capricieux avec
certaines versions d'Excel et/ou d'OS.
J'ai Excel 97 SR-2 avec Windows 98.


Indique un extrait de ton code.


Voila :

Private Sub TextBox1_Change()
Dim i As Integer
Dim c As Range
Dim rep As Integer

TextBox1.SetFocus
If TextBox1.Text = "" Then Exit Sub

With Worksheets("Synth").Columns(1)
Set c = .Find(TextBox1.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
c.Select
TextBox2.Text = c.Value
End If
End With
If c Is Nothing Then
Range("A2").Select
TextBox2.Text = "*** Référence non trouvée ***"
TextBox2.ForeColor = RGB(255, 0, 0)
TextBox2.Font.Bold = True
TextBox2.TextAlign = fmTextAlignCenter
Else
TextBox2.ForeColor = RGB(0, 0, 0)
TextBox2.Font.Bold = False
TextBox2.TextAlign = fmTextAlignLeft
End If
End Sub
--
@+
HD