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

VBScript Discussion :

ouverture, enregistrement et fermeture d'un fichier Excel


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Mai 2011
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 14
    Par défaut ouverture, enregistrement et fermeture d'un fichier Excel
    Bonjour,

    Voici mon problème.
    Grâce à un VBscript j'exécute un code SAS qui exporte des données dans un fichier Excel. Ensuite VBScript ouvre ce fichier xls (pour permettre un traitement VBA à l'ouverture du fichier) l'enregistre et ferme le fichier. Cependant une copie de mon fichier Excel est placée dans "Mes documents" avec une extension .XLW . Cette copie m'empêche de fermer automatiquement mon fichier excel , car il me dit que l'emplacement est déjà occupé par le fichier .XLW et demande si je veux le remplacer.

    J'aimerais que la copie en XLW ne soit pas réalisée, mais je ne sais pas comment le faire ou je ne vois pas où le code le fait.

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Set objExcel = CreateObject("Excel.Application")
    	objExcel.Workbooks.Open("chemin\fichier.xls")
    	objExcel.visible = true
    	objExcel.workbooks.save("chemin\fichier.xls")
    	objExcel.workbooks.close("chemin\fichier.xls")
    Merci de votre aide !!!!!

  2. #2
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    Ensuite VBScript ouvre ce fichier xls (pour permettre un traitement VBA à l'ouverture du fichier) l'enregistre et ferme le fichier
    C'est une macro qui s'exécute ?
    C'est peut être elle qui fait la copie de fichier.

    Peux tu montrer le code de la macro ?

  3. #3
    Membre averti
    Inscrit en
    Mai 2011
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 14
    Par défaut
    Voici le code entier, le debut à été créer par SAS guide en ordonnançant un projet il y a juste la partie que j'ai indiqué plus haut que j'ai rajouté et qui me crée le fichier XLW
    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
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    'chemin="L:\Campagnes\11n11\preparation\1 - Inscriptions a l operation\Diffusion\validation HP au 2009_03_05.xls"
     
    '*****************************************************************************************************************
    '__________________________________________   Exécute le code SAS   ______________________________________________
     
    '******************************************************************************************************************
    Dim app
    Call dowork
     
    'shut down the app
    If not (app Is Nothing) Then
        app.Quit
        Set app = Nothing
    End If
     
    sub dowork()
        On Error Resume Next
        '----
        ' Start up Enterprise Guide using the project name
        '----
        Dim prjName
        Dim prjObject
     
        prjName = "L:\Univers\VBO\Projet.egp"    'Project Name
     
        Set app = CreateObject("SASEGObjectModel.Application.4")
        If Checkerror("CreateObject") = True Then
            Exit Sub
        End If
     
        '-----
        ' open the project
        '-----
        Set prjObject = app.Open(prjName,"")
        If Checkerror("app.Open") = True Then
            Exit Sub
        End If
     
     
        '-----
        ' run the project
        '-----
        prjObject.run
        If Checkerror("Project.run") = True Then
            Exit Sub
        End If
     
     
        '-----
        ' Save the new project
        '-----
        'prjObject.Save
        'If Checkerror("Project.Save") = True Then
        '    Exit Sub
        'End If
     
        '-----
        ' Close the project
        '-----
        prjObject.Close
        If Checkerror("Project.Close") = True Then
            Exit Sub
        End If
    	'*******************************************************************************************************************************
    	'______________________________   ouvre, enregistre puis ferme le fichier Excel   _______________________________________________
     
    	'*******************************************************************************************************************************
    	Set objExcel = CreateObject("Excel.Application")
    	objExcel.Workbooks.Open("chamin\fichier.xls")
    	objExcel.visible = true
    	'objExcel.Save = true
    	objExcel.workbooks.save("chemin\fichier.xls")
    	'objExcel.workbooks.close("chemin\fichier.xls")
    	'objExcel.Application.Quit
     
     
    End Sub
     
    Function Checkerror(fnName)
        Checkerror = False
     
        Dim strmsg
        Dim errNum
     
        If Err.Number <> 0 Then
            strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description
            'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.
            Checkerror = True
        End If
     
    End Function

  4. #4
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    C'est quoi le :
    traitement VBA à l'ouverture du fichier
    Une macro ?
    Si oui peux tu montrer le code ?

Discussions similaires

  1. Réponses: 8
    Dernier message: 20/09/2007, 10h31
  2. execution de code a la fermeture d un fichier excell
    Par levac dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 07/07/2007, 19h26
  3. {VBA excel}OUverture,Extraction et Copie d'un fichier Excel dans un autre
    Par Thomas69 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 01/06/2007, 09h43
  4. enregistrer les données sur un fichier excel
    Par thunderpat dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 29/05/2007, 17h00
  5. Réponses: 6
    Dernier message: 12/01/2007, 14h33

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