IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

VB Excel enregistrer un fichier


Sujet :

Macros et VBA Excel

  1. #1
    Membre confirmé
    Femme Profil pro
    Analyste d'exploitation
    Inscrit en
    Septembre 2014
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Analyste d'exploitation

    Informations forums :
    Inscription : Septembre 2014
    Messages : 59
    Par défaut VB Excel enregistrer un fichier
    Bonjour,

    J'aimerais enregistrer un fichier Excel à l'aide d'un bouton.

    J'aimerais remplacer ce qui est en gras par le contenu de la cellule E8, comment est-ce possible?

    Un gros merci à celui qui m'aidera!!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    Function CreerChemin(strPath As String) As String
        Dim fso
        Set fso = CreateObject("scripting.filesystemobject")
        
        If Len(strPath) = 0 Then
            strPath = ActiveWorkbook.Path & Format(Now, "YYYY-MM-DD") & "\"
        End If
        
        If Right(strPath, 1) <> "\" Then
            strPath = strPath & "\"
        End If
        
        If Not fso.FolderExists(strPath) Then
            fso.CreateFolder (strPath)
        End If
        Set fso = Nothing
        CreerChemin = strPath
    End Function

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 609
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 609
    Par défaut
    Bonjour,

    Si E8 est une partie du chemin, ceci peut-être ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strPath = ActiveWorkbook.Path & "\" & Range("E8") & "\"

  3. #3
    Membre confirmé
    Femme Profil pro
    Analyste d'exploitation
    Inscrit en
    Septembre 2014
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Analyste d'exploitation

    Informations forums :
    Inscription : Septembre 2014
    Messages : 59
    Par défaut
    Bonjour,

    J'ai essayé ce code, et ça ne fonctionne toujours pas, il écrit la date du jour encore.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
     
    Function CreerChemin(strPath As String) As String
        Dim fso
        Set fso = CreateObject("scripting.filesystemobject")
     
        If Len(strPath) = 0 Then
            strPath = ActiveWorkbook.Path & feuille.Range("E8").Value & "\"
        End If
     
        If Right(strPath, 1) <> "\" Then
            strPath = strPath & "\"
        End If
     
        If Not fso.FolderExists(strPath) Then
            fso.CreateFolder (strPath)
        End If
        Set fso = Nothing
        CreerChemin = strPath
    End Function

  4. #4
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 609
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 609
    Par défaut
    D'une part, que vaut feuille puisqu'on ne voit pas sa déclaration ?
    Et qu'y a-t-il en E8 de cette... feuille ?
    Finalement où écrit-il la date ? dans le nom du répertoire ?

    ceci dit, si tu veux créer un sous-répertoire, chaque répertoire ou sous-répertoire doit exister auparavant
    i.e. si tu veux créer c:\a\b\c, le répertoire c:\a\b doit exister
    Par contre, je ne connais pas vraiment FileSystemObject... Peut-être est-il capable de créer une arborescence d'un seul appel (?)
    J'ai habitude d'utiliser MkDir()

  5. #5
    Expert confirmé
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Par défaut
    Salut,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Option Explicit
     
    Private Declare Function SHCreateDirectoryEx Lib "Shell32.dll" Alias "SHCreateDirectoryExA" _
                                                 (ByVal hwnd As Long, ByVal pszPath As String, ByVal lngsec As Long) As Long
     
    Private Function CreationDossier(sDossier) As Long
    Dim Rep As Long
        ' Pour valeur retournée par Rep
        '   Voir http://msdn.microsoft.com/en-us/library/bb762131(VS.85).aspx
        '   et   http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx
        Rep = SHCreateDirectoryEx(0&, sDossier, 0&)
    End Function
    Rajouter qqch du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Private Function NomDossierValide(sChaine As String) As Boolean
    Dim i As Long
    Const CaracInterdits As String = """*/:<>?[\]|"
        NomDossierValide = True
        If Len(sChaine) = 0 Then
            NomDossierValide = False
            Exit Function
        End If
        For i = 1 To Len(CaracInterdits)
            If InStr(sChaine, Mid$(CaracInterdits, i, 1)) > 0 Then
                NomDossierValide = False
                Exit Function
            End If
        Next i
    End Function

Discussions similaires

  1. Réponses: 3
    Dernier message: 02/04/2007, 22h52
  2. [VBA-E] une macro qui enregistre mon fichier Excel
    Par Djohn dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 02/03/2007, 12h47
  3. [VBA]enregistrer en fichier excel en macro
    Par jazziestan dans le forum SDK
    Réponses: 12
    Dernier message: 29/12/2006, 11h07
  4. [Excel] Enregistrer un fichier Excel côté client
    Par scorpking dans le forum Bibliothèques et frameworks
    Réponses: 14
    Dernier message: 18/07/2006, 12h10
  5. Ouvrire ou Enregistrer un Fichier Excel
    Par jo281 dans le forum ASP
    Réponses: 1
    Dernier message: 13/12/2005, 19h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo