fichier en variable avec workbook open

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

jopont

XLDnaute Impliqué
Bonjour,
J'utilise la fonction workbooks open,j'aimerais pouvoir dans la variable ci-dessous allez ouvrir le fichier correspondant au mois choisi par un contrôle monthview.

Je précise également que mes fichier se nomme 01-jan, 02-fev,03-mar,....,09-septembre...

chemin = "\\Gtsud\gtsaffichage\Planning\Gestion SPV\ANNEE 2010\GARDES\mois choisi.xls"


merci
 
Re : fichier en variable avec workbook open

Bonsoir Jopont 🙂,
Je précise également que mes fichier se nomme 01-jan, 02-fev,03-mar,....,09-septembre...
Il faudrait savoir, 09-sep ou 09-septembre 😕...
Ensuite, que renvoie ton contrôle MonthView (le premier jour du mois, je pense, mais faudrait vérifier avec un MsgBox...) ?
Si c'est le cas, Format(MoisChoisis, "mm-mmm") devrait te donner le nom de ton fichier (attention, avec les accents, soit "02-fév") et ton code devrait être
Code:
chemin = "\\Gtsud\gtsaffichage\Planning\Gestion SPV\ANNEE 2010\GARDES\" & Format(MoisChoisis, "mm-mmm") & ".xls"
Bonne soirée 😎
 
Re : fichier en variable avec workbook open

Bonjour à tous


En t'inspirant de cet exemple, tu dois pouvoir solutionner ton problème


Code:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Dim NomFichier$
NomFichier = "12-décembre.xls"
If NomFichier Like Month(MonthView1.Value) & "-*" Then
MsgBox "ok"
End If
End Sub
 
Re : fichier en variable avec workbook open

Re 🙂,
Avec un select Case
Code:
Select Case Month(MonthView1.Value)
Case 1
NomFichier = "01-jan.xls"
Case 2
NomFichier = "02-fev.xls"
...
End Select
Mais le créateur des fichiers est un abruti 😛...
Bonne soirée 😎
 
Re : fichier en variable avec workbook open

Re


(il y a dans c:\toto un fichier nommé : 12-décembre.xls)

Si je clique sur un date affichée dans l'userform
avec ce code, le fichier s'ouvre bien.

Code:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Dim NomFichier$, Chemin$
Chemin = "C:\Toto\"
NomFichier = Format(MonthView1.Value, "mm-mmmm") & ".xls"
Workbooks.Open (Chemin & NomFichier)
End Sub
 
Re : fichier en variable avec workbook open

Re 🙂,
J'avais pensé à un select case, mais où dois mettre select case dans le code.
J'utilise déjà un code sur événement cliquable de monthview, je ne voudrais pas perturbé ce code.
Ok, mais si on a pas ton code, comment te dire où mettre le Select Case 😛?
@ Stapple : Oui Jean-Marie, chez moi aussi, mais si c'est Janvier, il faudrait "mm-mmm", et pour Février, Replace(Format(MonthView1.Value, "mm-mmm"), "é", "e"), je te cause pas du casse-tête 😀 (d'où mon appréciation sur l'abruti qui a créé les fichiers de départ 😱).
Bonne soirée 😎
 
Re : fichier en variable avec workbook open

lorsque je clique sur le bouton rien ne se déclenche :

Private Sub CommandButton2_Click()
Dim f As Long, V1 As String, V3 As String, colonnspv As Long, chemin As String, NomFichier$

NomFichier = "12-dec.xls"
If NomFichier Like Month(MonthView1.Value) & "-*" Then
Application.Visible = False





chemin = "\\reseau\fichiermois\"
Workbooks.Open (chemin & NomFichier)

Label31.Caption = Day(MonthView1) * 4 + 3


colonnspv = Day(MonthView1) * 4 + 3
Label30.Caption = Cells(13, colonnspv + 4).Text
Sheets(1).Activate
With Sheets(1)
For f = 4 To 58
If .Cells(f, colonnspv + 1) = "SO" Or .Cells(f, colonnspv + 1) = "HDJ" Or .Cells(f, colonnspv + 1) = "HD" Then
V1 = V1 & Cells(f, 3) & "." & Cells(f, 4) & Chr(10)
Label27.Caption = V1

End If
If .Cells(f, colonnspv + 3) = "HDN" Or .Cells(f, colonnspv + 3) = "SON" Or .Cells(f, colonnspv + 3) = "HD" Then
V3 = V3 & Cells(f, 3) & "." & Cells(f, 4) & Chr(10)
Label28.Caption = V3
End If
If .Cells(f, colonnspv + 4) = "HDN" Or .Cells(f, colonnspv + 4) = "SON" Or .Cells(f, colonnspv + 3) = "HD" Then
V4 = V4 & Cells(f, 3) & "." & Cells(f, 4) & Chr(10)
Label29.Caption = V4
End If
Next
End With
ActiveWorkbook.Close SaveChanges:=False
Application.Visible = True
End If



End Sub
 
Re : fichier en variable avec workbook open

le code ressemble à ça

Case 2
Application.Visible = False
NomFichier = "02-fev.xls"
chemin = "\\...\fichiers\"
Workbooks.Open (chemin & NomFichier)
colonnspv = Day(MonthView1) * 4 + 3
Label30.Caption = Cells(13, colonnspv + 4).Text

With Sheets(1)
For f = 4 To 58
If .Cells(f, colonnspv + 1) = "SO" Or .Cells(f, colonnspv + 1) = "HDJ" Or .Cells(f, colonnspv + 1) = "HD" Or .Cells(f, colonnspv + 1) = "SOJ" Then
V1 = V1 & Cells(f, 3) & "." & Cells(f, 4) & Chr(10)
Label27.Caption = V1

End If
If .Cells(f, colonnspv + 3) = "HDN" Or .Cells(f, colonnspv + 3) = "SON" Or .Cells(f, colonnspv + 3) = "HD" Then
V3 = V3 & Cells(f, 3) & "." & Cells(f, 4) & Chr(10)
Label28.Caption = V3
End If
If .Cells(f, colonnspv + 4) = "HDN" Or .Cells(f, colonnspv + 4) = "SON" Or .Cells(f, colonnspv + 3) = "HD" Then
V4 = V4 & Cells(f, 3) & "." & Cells(f, 4) & Chr(10)
Label29.Caption = V4
End If
Next
End With
ActiveWorkbook.Close SaveChanges:=False
Application.Visible = True
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD
Retour