probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

georgesdelta

XLDnaute Nouveau
l'idée de la macro et si L1 = 2 alors c une facture a enregistrer dans le dossier BILLS
si L1 = 1 alors c un devis a enregistrer dans le dossier BILLS OLD


Sauf que le fichier s'enregistrer dans le dernier dossier utiliser pour une sauvegarde, donc la macro ne fonctionne pas


j'ai lu sur internet que ChDir ne fonctionne pas sous mac, confirmer vous ?


En vous remerciant d'avance.








Sub GENERERFACTURE()
Dim ESSAI As String
Dim NomFichier As String
Dim C As String
Dim facture As String
Dim commande As String
Dim jour As String

ESSAI = "MACINTOSH HD:Users:stuart:Desktop:BILLS"

commande = Range("e3").Value
facture = Range("f9").Value
jour = Day(Date) & "-" & Month(Date) & "-" & Year(Date)

NomFichier = facture & " " & commande & " " & jour
C = ESSAI & ":" & NomFichier




If Range("L1") = 2 Then
'Copie de la facture et enregistrement

ActiveSheet.Unprotect
ActiveSheet.Buttons.Add(591.75, 113.25, 150, 78.75).Select
ActiveSheet.Buttons.Add(844.5, 83.25, 170.25, 99).Select
Sheets("Facture").Copy Before:=Sheets(1)
ActiveWindow.SmallScroll Down:=21
Range("J1:W53").Select
Range("W53").Activate
ActiveSheet.Unprotect
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=-57
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 1
Sheets("Facture").Select
Range("E3:G7").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("E3:G3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B17:E17").Select
Range("G1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("I5:K39").Select
Selection.ClearContents
Selection.Delete Shift:=xlToLeft
Range("G1").Select

Sheets("Facture").Select
Range("D9:E10").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("D9:E10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("G1").Select




If Range("L1") = 2 Then
ChDir ESSAI

End If


ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=NomFichier, FileFormat:=57
ActiveWorkbook.Close

MsgBox "La facture a bien ŽtŽ enregistrŽe sous le nom : " & vbCrLf & C

End If

'Copie du devis et enregistrement


Dim DEVIS As String
Dim CHEMDEVIS As String
Dim ESSAI2 As String
Dim D As String
Dim E As String


D = Range("E3").Value
E = Range("F9").Value
DEVIS = E & " " & D
ESSAI2 = "MACINTOSH HD:Users:stuart:Desktop:BILLS OLD"
CHEMDEVIS = ESSAI2 & ":" & DEVIS

If Range("L1") = 1 Then

ActiveSheet.Unprotect
ActiveSheet.Buttons.Add(591.75, 113.25, 150, 78.75).Select
ActiveSheet.Buttons.Add(844.5, 83.25, 170.25, 99).Select
Sheets("Facture").Copy Before:=Sheets(1)
ActiveWindow.SmallScroll Down:=21
Range("J1:W53").Select
Range("W53").Activate
ActiveSheet.Unprotect
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=-57
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 1
Sheets("Facture").Select
Range("E3:G7").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("E3:G3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B17:E17").Select
Range("G1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("I5:K39").Select
Selection.ClearContents
Selection.Delete Shift:=xlToLeft
Range("G1").Select

Sheets("Facture").Select
Range("D9:E10").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("D9:E10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("G1").Select

If Range("L1") = 1 Then

ChDir ESSAI2

End If

ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=DEVIS, FileFormat:=57
ActiveWorkbook.Close

MsgBox "Le DEVIS a bien ŽtŽ enregistrŽe sous le nom : " & vbCrLf & DEVIS

End If



Sheets("Facture (2)").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Facture").Select
Range("i5:Q12").Select
ActiveSheet.Unprotect
Selection.Delete Shift:=xlToLeft
ActiveSheet.Protect
Range("L3").Select


End Sub
 

job75

XLDnaute Barbatruc
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Bonjour georgesdelta, bienvenue sur XLD,

Mais je vous conseille de (re)lire la Lien supprimé, pour le "bonjour" d'usage et le fichier à joindre...

ChDir n'est absolument pas nécessaire, voyez le fichier joint et ce code :

Code:
Const dossier1$ = "BILLS OLD" 'à adapter
Const dossier2$ = "BILLS" 'à adapter

Private Sub CommandButton1_Click() 'ENREGISTRER DEVIS
Enregistrer 0
End Sub

Private Sub CommandButton2_Click() 'ENREGISTRER FACTURE
Enregistrer 1
End Sub

Sub Enregistrer(choix As Byte)
Dim ref$, numero$, chemin$, nomfich$
ref = "B2" 'adresse à adapter
numero = "C2" 'adresse à adapter
chemin = ThisWorkbook.Path & "\" & IIf(choix, dossier2, dossier1) & "\"
If Dir(chemin, vbDirectory) = "" Then MkDir chemin 'création du dossier
Application.ScreenUpdating = False
Application.DisplayAlerts = False 'si le fichier a déjà été créé
With Workbooks.Add(xlWBATWorksheet).Sheets(1) 'nouveau document
  Cells.Copy .[A1]
  .[IV1].Copy .[IV1] 'vide la mémoire
  .UsedRange = Me.UsedRange.Value 'uniquement les valeurs
  .Range(ref) = IIf(choix, "FACTURE", "DEVIS") & " N°"
  .Name = IIf(choix, "FACTURE", "DEVIS")
  nomfich = .Range(ref) & .Range(numero) 'à compléter éventuellement
  On Error Resume Next
  Workbooks(nomfich).Close False 'si un fichier de ce nom est ouvert
  On Error GoTo 0
  .Parent.SaveAs chemin & nomfich
  .Parent.Close False
End With
MsgBox "Le fichier '" & nomfich & "' a été créé..."
End Sub
J'espère qu'il fonctionne sur MAC...

Suivant la version Excel le fichier est enregistré en .xlsx ou en .xls

A+
 

Pièces jointes

  • Devis-Facture(1).xlsm
    25.8 KB · Affichages: 25
Dernière édition:

job75

XLDnaute Barbatruc
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Re,

Fichier (2) un tout petit peu plus élaboré pour montrer comment adapter le code.

Edit : le fichier créé sera probablement envoyé au client, il est bon de protéger la feuille.

Mais le mieux est alors de créer un fichier PDF, nombreux exemples sur le forum.

A+
 

Pièces jointes

  • Devis-Facture(2).xlsm
    33.9 KB · Affichages: 25
Dernière édition:

job75

XLDnaute Barbatruc
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Re,

Sur ce fichier (3) la ligne :

Code:
.ExportAsFixedFormat xlTypePDF, chemin & nomfich 'fichier PDF
crée le fichier PDF, après mise en page (zone d'impression) ad hoc.

Sur Excel 2003 et versions antérieures cette méthode n'est pas possible.

Bonne fin de soirée.
 

Pièces jointes

  • Devis-Facture(3).xlsm
    42.2 KB · Affichages: 39

job75

XLDnaute Barbatruc
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Bonjour le forum,

Avec ce fichier (4) voici un projet à peu près terminé.

A+
 

Pièces jointes

  • Devis-Facture(4).xlsm
    57.7 KB · Affichages: 63

georgesdelta

XLDnaute Nouveau
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Bonjour tlm,

oui job75, j ai créer le post trop vite et je n ai pas fait attention a la politesse.

Job, je suis impressionné par tes réponses et je te remercie d avoir pris du temps pour résoudre mon problème.

malheureusement je n arrive pas a exploiter tes fichiers, quand je telecharge tes pieces jointes et que je les ouvrent, je ne suis quand lecture seule et les bouton macro ne fonctionnent pas et le tableau macro est vide, il faut que je passe par visual basic et je trouve les macro directement sur les onglets et non sous un nom de macro, je ne connais pas cette façon de faire et ducoup je ne m en sort pas. C dommage car en lisant tes macro je suis sur que cela résoudrai mon problème.

Aurait tu la possibilité de modifier directement mon fichier que je vais mettre en piece jointe.

Un grand merci d avance.
 

Pièces jointes

  • Facture-Devis vierges et SUMMARY 2.xlsm
    45.3 KB · Affichages: 42

job75

XLDnaute Barbatruc
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Bonsoir georgesdelta,

J'ai remplacé sur mon fichier les boutons ActiveX par des boutons Formulaires et adapté les macros.

Voyez le fichier joint, j'espère que ça ira bien chez vous.

C'est tout ce que je peux faire, c'est à vous d'utiliser au mieux ce que je vous ai proposé.

Il n'est pas question pour moi d'aller plus loin car je ne suis pas sur MAC.

Bonne nuit.
 

Pièces jointes

  • Devis-Facture avec boutons Formulaires(1).xlsm
    50.3 KB · Affichages: 35

georgesdelta

XLDnaute Nouveau
Re : probleme sur chemin d'enregistrement,chdir ne fonctionne sur mon mac

Re bonjour tlm,

d'abord un grand merci a job75 et kiki29 pour leurs aides. Je n'ai pas pu utiliser vos macros, trop complexes pour moi, mais j'ai réussi a trouver la solution.

Sub GENERERFACTURE()

Dim CHEMFACTURE As String
Dim NomFichier As String
Dim facture As String
Dim commande As String
Dim jour As String

CHEMFACTURE = "/Users/stuart/Desktop/BILLS/"
commande = Range("e3").Value
facture = Range("f9").Text
jour = Day(Date) & "-" & Month(Date) & "-" & Year(Date)
NomFichier = facture & " " & commande & " " & jour


If Range("L1") = 2 Then
'Copie de la facture et enregistrement

ActiveSheet.Unprotect
ActiveSheet.Buttons.Add(591.75, 113.25, 150, 78.75).Select
ActiveSheet.Buttons.Add(844.5, 83.25, 170.25, 99).Select
Sheets("Facture").Copy Before:=Sheets(1)
ActiveWindow.SmallScroll Down:=21
Range("J1:W53").Select
Range("W53").Activate
ActiveSheet.Unprotect
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=-57
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 1
Sheets("Facture").Select
Range("E3:G7").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("E3:G3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B17:E17").Select
Range("G1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("I5:K39").Select
Selection.ClearContents
Selection.Delete Shift:=xlToLeft
Range("G1").Select

Sheets("Facture").Select
Range("D9:E10").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("D9:E10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("G1").Select

ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:= _
CHEMFACTURE & NomFichier, _
FileFormat:=57, CreateBackup:=False
ActiveWorkbook.Close

MsgBox "La facture a bien ŽtŽ enregistrŽe sous le nom : " & CHEMFACTURE & NomFichier

End If

'Copie du devis et enregistrement


Dim DEVIS As String
Dim CHEMDEVIS As String
Dim D As String
Dim E As String


D = Range("E3").Value
E = Range("F9").Text
DEVIS = E & " " & D
CHEMDEVIS = "/Users/stuart/Desktop/BILLS OLD/DEVIS/"


If Range("L1") = 1 Then

ActiveSheet.Unprotect
ActiveSheet.Buttons.Add(591.75, 113.25, 150, 78.75).Select
ActiveSheet.Buttons.Add(844.5, 83.25, 170.25, 99).Select
Sheets("Facture").Copy Before:=Sheets(1)
ActiveWindow.SmallScroll Down:=21
Range("J1:W53").Select
Range("W53").Activate
ActiveSheet.Unprotect
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=-57
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 1
Sheets("Facture").Select
Range("E3:G7").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("E3:G3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B17:E17").Select
Range("G1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("I5:K39").Select
Selection.ClearContents
Selection.Delete Shift:=xlToLeft
Range("G1").Select

Sheets("Facture").Select
Range("D9:E10").Select
Selection.Copy
Sheets("Facture (2)").Select
Range("D9:E10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("G1").Select


MkDir CHEMDEVIS & D


ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:= _
CHEMDEVIS & D & "/" & DEVIS, _
FileFormat:=57, CreateBackup:=False
ActiveWorkbook.Close

MsgBox "Le devis a bien ŽtŽ enregistrŽ sous le nom : " & CHEMDEVIS & D & "/" & DEVIS


End If

Sheets("Facture (2)").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Facture").Select
Range("i5:Q12").Select
ActiveSheet.Unprotect
Selection.Delete Shift:=xlToLeft
ActiveSheet.Protect
Range("L3").Select
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 709
Messages
2 081 756
Membres
101 812
dernier inscrit
trufu