OVH Cloud OVH Cloud

Vba en VB....

1 réponse
Avatar
Hervé Frank-Dangel
Bon, ben, je croyais que ça serait simple, mais.....


comment faire pour passer ma macro vba en VB ???

(en conservant les userforms...)

le but est ensuite de pouvoir creer un exe (possible avec VB, mais pas avec
VBA :-( ... )

autre souci, meme en conservant le code, VB ne reconnait pas les fonction
worksheet etc... (logique...)

par quoi les remplacer ????

voici le code :
'API servant au calcul du temps (à supprimer après test avec ce qui va avec)
Private Declare Function GetTickCount Lib "Kernel32" () As Long
'en metant :
'1 TextBox nommé TxtMaxi pour le nombre de lignes
'1 TextBox nommé TxtPas pour le pas
'1 Label nommé LblMaxi pour indiquer le champ Maxi
'1 Label nommé LblPas pour indiquer le champ Pas
'1 Label nommé LblAffiche pour le pourcentage
'dont les propriétés :
'"BackStyle" = 0 (transparent)
'"ForeColor" = &H00FFFFFF& (Blanc)
'"Left" comme LblProgress
'"Width" de façon à pouvoir afficher 100%
'"Caption" = "100%" puis après avoir réglé Width supprimer
'1 CommadButton nommé CmdOK pour lancer la proc
'1 CommadButton nommé CmdAnnuler
'et la barre de progression nommée LblProgress
'avec False à la propriété "Visible" car elle sera
'affichée en temps voulue

'Sub demarre()
'progbar1.Show
'End Sub

Private Sub CmdAnnuler_Click()
Unload Me
End Sub

Private Sub CmdOK_Click()
Dim ProgressLargeur
Dim I As Long, J As Long
Dim Debut As Long
Debut = GetTickCount()
With progbar1
.TxtMaxi.Visible = False
.TxtPas.Visible = False
.LblMaxi.Visible = False
.LblPas.Visible = False
.Label1.Visible = True
.Label2.Visible = True
.Label3.Visible = True
.Label4.Visible = False
.CmdAnnuler.Visible = False
.CmdOK.Visible = False
.LblProgress.Visible = True
End With
ProgressLargeur = progbar1.LblProgress.Width
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual ' si applicable

LblProgress.Width = 0
' si une valeur non numérique dans les textbox
On Error GoTo Fin
'mets en commentaire la ligne
'que tu ne veux pas tester :
'ParLigne TxtMaxi, TxtPas, ProgressLargeur
ParTableau TxtMaxi, TxtPas, ProgressLargeur
Fin:
If Err.Number <> 0 Then
MsgBox "Valeurs non numériques !"
End If
Unload progbar1
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic ' si applicable
MsgBox Format((GetTickCount() - Debut) / 1000, "0" & " Mise en forme 00
secondes")
End Sub
Sub ParLigne(Maxi As Long, _
Pas As Integer, _
ByVal ProgressLargeur As Integer)
Dim I As Long, J As Long

J = 1

With Worksheets("Feuil1")
For I = 1 To Maxi Step Pas
.Rows(I).Copy Worksheets("Feuil2").Rows(J)
J = J + 1
LblProgress.Width = (I / Maxi) * ProgressLargeur
progbar1.Caption = CInt((I / Maxi) * 100) & "%"
With LblAffiche
.Caption = CInt((I / Maxi) * 100) & "%"
If LblProgress.Width < .Width Then
.Left = LblProgress.Left
Else
.Left = LblProgress.Width / 2
End If
End With
DoEvents
Next
End With
End Sub
Sub ParTableau(Maxi As Long, _
Pas As Integer, _
ByVal ProgressLargeur As Integer)
Dim Tbl
Dim I As Long
Dim J As Integer
Dim K As Long
Dim Colonne As Long
With Worksheets("Feuil1")
'recherche la dernière colonne
Colonne = .Cells.Find("*", .[A1], xlFormulas, , _
xlByColumns, xlPrevious).Column
'rempli le tableau
Tbl = .Range(.Cells(1, 1), .Cells(Maxi, Colonne))
End With
'déplace les valeurs dans le tableau
For I = 1 To Maxi Step Pas
K = K + 1
For J = 1 To Colonne
Tbl(K, J) = Tbl(I, J)
Next J
LblProgress.Width = (I / Maxi) * ProgressLargeur
progbar1.Caption = CInt((I / Maxi) * 100) & "% effectués"
With LblAffiche
.Caption = CInt((I / Maxi) * 100) & "%"
If LblProgress.Width < .Width Then
.Left = LblProgress.Left
Else
.Left = LblProgress.Width / 2
End If
End With
DoEvents
Next I
'colle le résultat dans la feuille
With Worksheets("Feuil2")
.Range(.Cells(1, 1), .Cells(K, Colonne)) = Tbl
Worksheets("Feuil2").Select
Cells.Select
Selection.Columns.AutoFit
Selection.Rows.AutoFit
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Range("A1").Select
End With
Erase Tbl
End Sub

1 réponse

Avatar
mousnynao
Bonjour,

Utiliser le sous-ensemble VBS de VB pour piloter Excel.
Vous trouverez ici une exemple d'un script VBS, il vous
suffit de l'adapter dans VB.

Les composantes VBS s'insére bien dans un prog VB.

http://www.oricom.ca/lupin/Document/ExcelVBS.txt

mousnynao!

-----Message d'origine-----
Bon, ben, je croyais que ça serait simple, mais.....


comment faire pour passer ma macro vba en VB ???

(en conservant les userforms...)

le but est ensuite de pouvoir creer un exe (possible avec
VB, mais pas avec

VBA :-( ... )

autre souci, meme en conservant le code, VB ne reconnait
pas les fonction

worksheet etc... (logique...)

par quoi les remplacer ????

voici le code :
'API servant au calcul du temps (à supprimer après test
avec ce qui va avec)

Private Declare Function GetTickCount Lib "Kernel32" ()
As Long

'en metant :
'1 TextBox nommé TxtMaxi pour le nombre de lignes
'1 TextBox nommé TxtPas pour le pas
'1 Label nommé LblMaxi pour indiquer le champ Maxi
'1 Label nommé LblPas pour indiquer le champ Pas
'1 Label nommé LblAffiche pour le pourcentage
'dont les propriétés :
'"BackStyle" = 0 (transparent)
'"ForeColor" = &H00FFFFFF& (Blanc)
'"Left" comme LblProgress
'"Width" de façon à pouvoir afficher 100%
'"Caption" = "100%" puis après avoir réglé Width
supprimer

'1 CommadButton nommé CmdOK pour lancer la proc
'1 CommadButton nommé CmdAnnuler
'et la barre de progression nommée LblProgress
'avec False à la propriété "Visible" car elle sera
'affichée en temps voulue

'Sub demarre()
'progbar1.Show
'End Sub

Private Sub CmdAnnuler_Click()
Unload Me
End Sub

Private Sub CmdOK_Click()
Dim ProgressLargeur
Dim I As Long, J As Long
Dim Debut As Long
Debut = GetTickCount()
With progbar1
.TxtMaxi.Visible = False
.TxtPas.Visible = False
.LblMaxi.Visible = False
.LblPas.Visible = False
.Label1.Visible = True
.Label2.Visible = True
.Label3.Visible = True
.Label4.Visible = False
.CmdAnnuler.Visible = False
.CmdOK.Visible = False
.LblProgress.Visible = True
End With
ProgressLargeur = progbar1.LblProgress.Width
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual ' si
applicable


LblProgress.Width = 0
' si une valeur non numérique dans les textbox
On Error GoTo Fin
'mets en commentaire la ligne
'que tu ne veux pas tester :
'ParLigne TxtMaxi, TxtPas, ProgressLargeur
ParTableau TxtMaxi, TxtPas, ProgressLargeur
Fin:
If Err.Number <> 0 Then
MsgBox "Valeurs non numériques !"
End If
Unload progbar1
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic ' si
applicable

MsgBox Format((GetTickCount() - Debut) / 1000, "0" & "
Mise en forme 00

secondes")
End Sub
Sub ParLigne(Maxi As Long, _
Pas As Integer, _
ByVal ProgressLargeur As Integer)
Dim I As Long, J As Long

J = 1

With Worksheets("Feuil1")
For I = 1 To Maxi Step Pas
.Rows(I).Copy Worksheets("Feuil2").Rows(J)
J = J + 1
LblProgress.Width = (I / Maxi) * ProgressLargeur
progbar1.Caption = CInt((I / Maxi) * 100) & "%"
With LblAffiche
.Caption = CInt((I / Maxi) * 100) & "%"
If LblProgress.Width < .Width Then
.Left = LblProgress.Left
Else
.Left = LblProgress.Width / 2
End If
End With
DoEvents
Next
End With
End Sub
Sub ParTableau(Maxi As Long, _
Pas As Integer, _
ByVal ProgressLargeur As Integer)
Dim Tbl
Dim I As Long
Dim J As Integer
Dim K As Long
Dim Colonne As Long
With Worksheets("Feuil1")
'recherche la dernière colonne
Colonne = .Cells.Find("*", .[A1], xlFormulas, , _
xlByColumns, xlPrevious).Column
'rempli le tableau
Tbl = .Range(.Cells(1, 1), .Cells(Maxi, Colonne))
End With
'déplace les valeurs dans le tableau
For I = 1 To Maxi Step Pas
K = K + 1
For J = 1 To Colonne
Tbl(K, J) = Tbl(I, J)
Next J
LblProgress.Width = (I / Maxi) * ProgressLargeur
progbar1.Caption = CInt((I / Maxi) * 100) & "%
effectués"

With LblAffiche
.Caption = CInt((I / Maxi) * 100) & "%"
If LblProgress.Width < .Width Then
.Left = LblProgress.Left
Else
.Left = LblProgress.Width / 2
End If
End With
DoEvents
Next I
'colle le résultat dans la feuille
With Worksheets("Feuil2")
.Range(.Cells(1, 1), .Cells(K, Colonne)) = Tbl
Worksheets("Feuil2").Select
Cells.Select
Selection.Columns.AutoFit
Selection.Rows.AutoFit
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Range("A1").Select
End With
Erase Tbl
End Sub




.