Excel Format textbox identique à cellule Source

Résolu/Fermé
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 - Modifié par elglouton le 29/11/2012 à 15:06
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 - 1 déc. 2012 à 23:56
Bonjour,

J'ai créer des Userform pour lequel je remplis des TextBox avec des données présent dans une feuille de calcul excel.
Existe il une façon de récupérer le format de cette cellule (différent en fonction des Cellules) afin de le représenter dans le textBox.

Est il aussi possible de faire apparaitre des textbox d'un userform en fonction des données présente dans un RowSource.
Si le RowSource est vide, je n'affiche pas mon textbox.
Si mon RowSource est plein j'affiche mon Textbox.

" 
" 
Option Explicit 
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ 
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long 
Private Declare Function GetWindowLong Lib "user32" Alias _ 
"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long 
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ 
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long _ 
, lParam As Any) As Long 
Private Declare Function ReleaseCapture Lib "user32" () As Long 

Private Sub CommandButtonMain_Click() 
Unload Me 
UserFormPushButton.Show 
End Sub 

Private Sub ImageSiemens_Click() 
Me.PrintForm 
End Sub 

Private Sub CommandButtonMaison_Click() 
Unload Me 
UserFormMainMenu.Show 
End Sub 

''''''Pour fermer par Double Click, peux être supprimer'''''' 
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
Unload Me 
End Sub 

''''''Pour permettre le déplacement du userform, peux être supprimer'''''' 
Private Sub UserForm_MouseDown(ByVal Button As Integer _ 
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) 
ReleaseCapture 
SendMessage FindWindow(vbNullString, Me.Caption), &HA1, 2, 0& 
End Sub 

Private Sub UserForm_Initialize() 
Dim hWnd As Long, Style As Long 

hWnd = FindWindow(vbNullString, Me.Caption) 
Style = GetWindowLong(hWnd, -16) And Not &HC00000 
SetWindowLong hWnd, -16, Style 
DrawMenuBar hWnd 


'Avoir le meme format dans CommandButtonHaut1_1 que dans ParametresFR!B165 
If IsEmpty(Sheets("ParametresFR").Range("B165")) Then 
CommandButtonHaut1_1.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_1.Caption = Sheets("ParametresFR").Range("B165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("C165")) Then 
CommandButtonHaut1_2.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_2.Caption = Sheets("ParametresFR").Range("C165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("D165")) Then 
CommandButtonHaut1_3.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_3.Caption = Sheets("ParametresFR").Range("D165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("E165")) Then 
CommandButtonHaut1_4.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_4.Caption = Sheets("ParametresFR").Range("E165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("F165")) Then 
CommandButtonHaut1_5.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_5.Caption = Sheets("ParametresFR").Range("F165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("G165")) Then 
CommandButtonHaut1_6.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_6.Caption = Sheets("ParametresFR").Range("G165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("H165")) Then 
CommandButtonHaut1_7.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_7.Caption = Sheets("ParametresFR").Range("H165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("I165")) Then 
CommandButtonHaut1_8.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_8.Caption = Sheets("ParametresFR").Range("I165").Value 
End If 
If IsEmpty(Sheets("ParametresFR").Range("J165")) Then 
CommandButtonHaut1_9.Visible = False 
Else 
UserFormForce1.CommandButtonHaut1_9.Caption = Sheets("ParametresFR").Range("J165").Value 
End If 

ComboBoxCentre1_1.RowSource = ("Connection") 
ComboBoxCentre1_2.RowSource = ("TypeES") 
ComboBoxCentre1_3.RowSource = ("Nombre") 
ComboBoxCentre1_4.RowSource = ("Nombre") 
ComboBoxCentre1_5.RowSource = ("Nombre") 
ComboBoxCentre1_6.RowSource = ("Type_de_données") 
ComboBoxCentre1_7.RowSource = ("Format") 
ComboBoxCentre1_8.RowSource = ("Nombre") 
ComboBoxCentre1_9.RowSource = ("Nombre") 

'RowSource à afficher si RowSource1_1 est plein 
ComboBoxCentre2_1.RowSource = ("Connection") 
ComboBoxCentre2_2.RowSource = ("TypeES") 
ComboBoxCentre2_3.RowSource = ("Nombre") 
ComboBoxCentre2_4.RowSource = ("Nombre") 
ComboBoxCentre2_5.RowSource = ("Nombre") 
ComboBoxCentre2_6.RowSource = ("Type_de_données") 
ComboBoxCentre2_7.RowSource = ("Format") 
ComboBoxCentre2_8.RowSource = ("Nombre") 
ComboBoxCentre2_9.RowSource = ("Nombre") 

'RowSource à afficher si RowSource2_1 est plein 
ComboBoxCentre3_1.RowSource = ("Connection") 
ComboBoxCentre3_2.RowSource = ("TypeES") 
ComboBoxCentre3_3.RowSource = ("Nombre") 
ComboBoxCentre3_4.RowSource = ("Nombre") 
ComboBoxCentre3_5.RowSource = ("Nombre") 
ComboBoxCentre3_6.RowSource = ("Type_de_données") 
ComboBoxCentre3_7.RowSource = ("Format") 
ComboBoxCentre3_8.RowSource = ("Nombre") 
ComboBoxCentre3_9.RowSource = ("Nombre") 
End Sub" 


Connection (STILMAS ; <No PLC>)
TypeES (BD;I;O;M;T;C)
Type de données (WORLD;INT;DWORLD;DINT;REAL;TIMER;COUNTER)
Format (T;BIN;HEX;DEC;C)

En espérant avoir été clair je vous remerci par avance

            
                
A voir également:

2 réponses

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
30 nov. 2012 à 11:30
Bonjour,

J'ai créer des Userform pour lequel je remplis des TextBox Ce ne sont pas des TextBox mais des Combobox.

Si j'ai compris ce que vous voulez:

'Exemple pour ComboBoxCentre1_1.RowSource
'RowSource à afficher si RowSource1_1 est plein
If ComboBoxCentre1_1.RowSource <> "" Then
  ComboBoxCentre2_1.RowSource = ("Connection")
  ComboBoxCentre2_2.RowSource = ("TypeES")
  ComboBoxCentre2_3.RowSource = ("Nombre")
  ComboBoxCentre2_4.RowSource = ("Nombre")
  ComboBoxCentre2_5.RowSource = ("Nombre")
  ComboBoxCentre2_6.RowSource = ("Type_de_données")
  ComboBoxCentre2_7.RowSource = ("Format")
  ComboBoxCentre2_8.RowSource = ("Nombre")
  ComboBoxCentre2_9.RowSource = ("Nombre")
  ComboBoxCentre2_1.Visible = True
  ComboBoxCentre2_2.Visible = True
  ComboBoxCentre2_3.Visible = True
  ComboBoxCentre2_4.Visible = True
  ComboBoxCentre2_5.Visible = True
  ComboBoxCentre2_6.Visible = True
  ComboBoxCentre2_7.Visible = True
  ComboBoxCentre2_8.Visible = True
  ComboBoxCentre2_9.Visible = True
Else
  ComboBoxCentre2_1.Visible = False
  ComboBoxCentre2_2.Visible = False
  ComboBoxCentre2_3.Visible = False
  ComboBoxCentre2_4.Visible = False
  ComboBoxCentre2_5.Visible = False
  ComboBoxCentre2_6.Visible = False
  ComboBoxCentre2_7.Visible = False
  ComboBoxCentre2_8.Visible = False
  ComboBoxCentre2_9.Visible = False
End If


A+
2
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 1
Modifié par elglouton le 30/11/2012 à 13:43
Merci pour votre réponse je test ça des que possible
Et en effet petit erreur d'intitulé c'est bien des ComboBox .
Et sinon pour ce qui est de la récupérations du Format des cellules pour les éléments des userform pensez vous que cela soit possible ?
0
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 1
30 nov. 2012 à 21:28
Nikel çà fonctionne j'ai du mettre un

Private Sub ComboBoxCentre1_1_Change()
Call UserForm_Initialize
End Sub

Un grand merci à vous et bon WeekEnd
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
1 déc. 2012 à 08:07
Bonjour,

Et sinon pour ce qui est de la récupérations du Format des cellules.... Si vous parlez de style, police, couleur: Oui, une fois le choix fait.

A+
0
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 1
1 déc. 2012 à 10:08
C'est plus au niveau du format des nombres (1 décimale ou plus , date ,heure.
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
1 déc. 2012 à 10:50
Re,

Exemple de formatage info cellules excel dans Combobox UserForm

Private Sub ComboBox1_Change()
  'format date: jj/mm/aaaa
  ComboBox1 = CDate(ComboBox1)
End Sub

Private Sub ComboBox2_Change()
  'Format nombre: 12.12 (attention:arrondi!!!)
  ComboBox2 = Format(ComboBox2, "00.00")
  'Format nombre: 12.12 sans arrondi
  ComboBox2 = Format(ComboBox2, "##.##")
End Sub


Bonne suite
0
eriiic Messages postés 24569 Date d'inscription mardi 11 septembre 2007 Statut Contributeur Dernière intervention 28 décembre 2023 7 212
Modifié par eriiic le 1/12/2012 à 16:30
Bonjour,

C'est sympa un userform sans bouton de fermeture...
Est il donc possible de faire que le userform voit le contenu des cellules dans le format des cellules excel.
textbox1 = Format([Feuil1!A1].Value, [Feuil1!A1].NumberFormat)

eric

Jamais tu ne répondras à un mp non sollicité...
Bon, ça c'est fait.
2
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 1
1 déc. 2012 à 23:13
Merci pour la réponse Eriiic,
En effet j'aurais du prévenir pour la fermeture par double click.
0
elglouton Messages postés 189 Date d'inscription dimanche 19 avril 2009 Statut Membre Dernière intervention 11 novembre 2022 1
1 déc. 2012 à 23:56
Un grand Merci à tous les deux,
Tout à l'air de fonctionner comme voulut vous êtes parfait
Encore merci pour votre aide
0