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 :

tri sous excel 2007 via macro


Sujet :

Macros et VBA Excel

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2007
    Messages : 5
    Points : 2
    Points
    2
    Par défaut tri sous excel 2007 via macro
    bonjour
    en voulant trier, avec les fonctions de tri d'excel 2007, des données récupérer sur un fichier xml. je me retrouve avec l' erreur :


    Erreur d'exécution '-2147417851 (80010105)'
    Erreur Automation
    le serveur a généré une exception.

    code :

    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
    ...
     
    fichierxml = "j:\test\11.xml"
     
    XSLT_StyleSheet = "<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">" & vbCrLf & _
                  "  <xsl:output method=""text"" indent=""no"" encoding=""ISO-8859-1""/>" & vbCrLf & _
                  "  <xsl:template match=""/"">" & vbCrLf & _
                  "    <xsl:for-each select=""/billets/billet"">" & vbCrLf & _
                  "      <xsl:value-of select=""PN""/><xsl:text>&#x9;</xsl:text>" & vbCrLf & _
                  "      <xsl:value-of select=""SD""/><xsl:text>&#x9;</xsl:text>" & vbCrLf & _
                  "      <xsl:value-of select=""MC""/><xsl:text>&#x9;</xsl:text>" & vbCrLf & _
                  "      <xsl:value-of select=""TN""/><xsl:text>&#x9;</xsl:text>" & vbCrLf & _
                  "      <xsl:value-of select=""LS""/><xsl:text>&#x9;</xsl:text>" & vbCrLf & _
                  "      <xsl:text>&#xD;&#xA;</xsl:text>" & vbCrLf & _
                  "    </xsl:for-each>" & vbCrLf & _
                  "  </xsl:template>" & vbCrLf & _
                  "</xsl:stylesheet>"
     
    	Dim StyleSheet
        	Set StyleSheet = CreateObject("Msxml2.DOMDocument.4.0")
        	StyleSheet.async = False
        	StyleSheet.LoadXML XSLT_StyleSheet
     
        	Dim fichier
        	Set fichier = CreateObject("Msxml2.DOMDocument.4.0")
        	fichier.async = False
        	fichier.Load fichierxml
     
     
    	Dim data
        	data = fichier.transformNode(StyleSheet)
     
    	Dim objFSO, objFile, appliExcel
        	Set objFSO = CreateObject("Scripting.FileSystemObject")
     
        	Set objFile = objFSO.CreateTextFile("j:\test\test.xls")
        	objFile.Write data
        	objFile.Close
     
        	Set appliExcel = GetObject("", "excel.application")
        	appliExcel.Visible = True
     
     	appliExcel.Workbooks.Open ("j:\test\test.xls")
    	i = CLng(appliExcel.Worksheets(1).UsedRange.Rows.Count)
        	SortColumnA = "A1:A" & i
    	SortColumnB = "B1:B" & i
        	SortColumnC = "C1:C" & i
        	SortColumnA_E = "A1:E" & i
            appliExcel.Worksheets(1).Range(SortColumnA_E).Select
     
     
            With appliExcel
             ActiveWorkbook.Worksheets(1).Sort.SortFields.Clear
             ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range(SortColumnA), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
             ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range(SortColumnB), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
             ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range(SortColumnC), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
             With ActiveWorkbook.Worksheets(1).Sort
                .SetRange Range(SortColumnA_E)
                .Header = Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes            
    	    .MatchCase = False
                .Orientation = Excel.Constants.xlTopToBottom
                .SortMethod = Excel.XlSortMethod.xlPinYin
                .Apply
     
             End With
            End With
     
    ...

    l'affichage sur le feuille excel s'effectue sans probleme. la lecture des cellules aussi
    ca coince vraiment au tri.


    quelqu un aurait une idée
    un grand merci d'avance.

  2. #2
    Expert éminent
    Avatar de fring
    Homme Profil pro
    Engineering
    Inscrit en
    Février 2008
    Messages
    3 900
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : Belgique

    Informations professionnelles :
    Activité : Engineering

    Informations forums :
    Inscription : Février 2008
    Messages : 3 900
    Points : 7 964
    Points
    7 964
    Par défaut
    Bonjour,

    Essaye en ajoutant un point devant ActiveWorkbook pour le lier au With appliExcel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    With appliExcel
        .ActiveWorkbook.Worksheets(1).Sort.SortFields.Clear
        .ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range(SortColumnA), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range(SortColumnB), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range(SortColumnC), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With .ActiveWorkbook.Worksheets(1).Sort
            .SetRange Range(SortColumnA_E)
            .Header = Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes            
            .MatchCase = False
            .Orientation = Excel.Constants.xlTopToBottom
            .SortMethod = Excel.XlSortMethod.xlPinYin
            .Apply
        End With
    End With

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2007
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    toujours la même erreur (avec le point ".")

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2007
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    j'ai du faire le tri via une feuille de style avant de transférer sur une feuille Excel.

    j'ai constaté que les fichiers que j'ai générer avec:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set objFile = objFSO.CreateTextFile("j:\test\test.xls")
    ou avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set appliExcel = GetObject("", "excel.application")
    une fois enregistrer s'ouvraient directement via Excel avec une mention que le fichier porte une extension qui correspond pas au contenu

    Merci Fring

Discussions similaires

  1. [E-07] Macro création d'un graphique sous Excel 2007
    Par JMPS.VBA dans le forum Contribuez
    Réponses: 1
    Dernier message: 19/11/2014, 18h24
  2. Probleme macro sous Excel 2007
    Par vladimire dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 13/02/2009, 15h36
  3. Réponses: 5
    Dernier message: 22/04/2008, 13h53
  4. Lenteurs de macros VBA sous Excel 2007 vs Excel 2003
    Par nicotab dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/11/2007, 18h47

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