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

VB.NET Discussion :

Macro Excel 2007 dans VB.net 2005


Sujet :

VB.NET

  1. #1
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2008
    Messages
    161
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mars 2008
    Messages : 161
    Points : 166
    Points
    166
    Par défaut Macro Excel 2007 dans VB.net 2005
    Bonjour à tous,

    J'ai créé une macro avec Excel 2007 et je voudrais intégrer le code généré dans une application VB.Net 2005, juste pour faire le design de ma feuille Excel. Mais je ne m'en sort pas du tout. Voici le code géné avec les quelques modification que j'ai apportée. Donnez moi un coup de point s'il vous plait.

    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
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    Sub Mise_En_Forme_Excel()
    '
    ' Macro1 Macro
    '
    Dim monda As New OleDb.OleDbDataAdapter
    Dim App_Excel As Microsoft.Office.Interop.Excel.Application
    Dim Classeur As Microsoft.Office.Interop.Excel.Workbook
    Dim Feuille As Microsoft.Office.Interop.Excel.Worksheet
     
     
    'Columns(1).EntireColumn.AutoFit()
    Feuille.Columns(1).EntireColumn.AutoFit()
    Feuille.Columns(2).EntireColumn.AutoFit()
    Feuille.Columns(3).EntireColumn.AutoFit()
    Feuille.Columns(4).EntireColumn.AutoFit()
    Feuille.Columns(5).EntireColumn.AutoFit()
    Feuille.Range("A4:E").Select()
     
    With Feuille.Range("A4:E4").Font
    .Bold = True
    .Name = "Calibri"
    .Size = 12
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = Microsoft.Office.Interop.Excel.XlUnderlineStyle.xlUnderlineStyleNone 'xlUnderlineStyleNone
    .ThemeColor = Microsoft.Office.Interop.Excel.XlThemeColor.xlThemeColorLight1 'xlThemeColorLight1
    .TintAndShade = 0
    .ThemeFont = Microsoft.Office.Interop.Excel.XlThemeFont.xlThemeFontMinor 'xlThemeFontMinor
    End With
     
    Feuille.Range("A4:E4").Borders(XlBordersIndex.xlDiagonalDown).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone '(xlDiagonalDown).LineStyle = xlNone
    Feuille.Range("A4:E4").Borders(XlBordersIndex.xlDiagonalUp).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone '(xlDiagonalUp).LineStyle = xlNone
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeLeft) '(xlEdgeLeft)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeTop) '(xlEdgeTop)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").BordersBorders(XlBordersIndex.xlEdgeBottom) '(xlEdgeBottom)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeRight) '(xlEdgeRight)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlInsideVertical)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlInsideHorizontal)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    Feuille.Range("A4:E4").Borders(XlBordersIndex.xlDiagonalDown).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone 'xlNone
    Feuille.Range("A4:E4").Borders(XlBordersIndex.xlDiagonalUp).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone 'xlNone
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeLeft) '(xlEdgeLeft)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeTop)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    ' .Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeBottom)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlDouble 'xlDouble
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThick
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlEdgeRight)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A4:E4").Borders(XlBordersIndex.xlInsideVertical)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
     
    Feuille.Range("A4:E4").Borders(XlBordersIndex.xlInsideHorizontal).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone 'xlNone
    Feuille.Range("A5:E1093").Select()
    Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlDiagonalDown).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone 'xlNone
    Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlDiagonalUp).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone 'xlNone
    With Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlEdgeLeft)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlEdgeTop)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlEdgeBottom)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlEdgeRight)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlInsideVertical)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    With Feuille.Range("A5:E1093").Borders(XlBordersIndex.xlInsideHorizontal)
    .LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous 'xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    '.Weight = xlThin
    End With
    Feuille.Range("A4:E4").Select()
    With Feuille.Range("A4:E4").Interior
    .Pattern = Microsoft.Office.Interop.Excel.XlPattern.xlPatternSolid 'xlSolid
    .PatternColorIndex = Microsoft.Office.Interop.Excel.XlPattern.xlPatternAutomatic 'xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    With Feuille.Range("A4:E4").Font
    .Color = -3394816
    .TintAndShade = 0
    End With
     
    Feuille("Feuil1").Select()
    Sheets("Feuil1").Name = "Liste generale"
    Range("B2").Select()
    Sheets("Liste generale").Select()
    End Sub

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 749
    Points
    39 749
    Par défaut
    Citation Envoyé par peregna2007 Voir le message
    Donnez moi un coup de point s'il vous plait
    Avec plaisir ! tiens, le voilà :
    (désolé, j'ai pas pu résister...)

    Plus sérieusement, si tu nous disais ce qui ne va pas exactement ? Parce que "je ne m'en sors pas", c'est un peu vague, et ça ne nous permet pas vraiment de t'aider...
    En lisant vite fait ce code, je remarque déjà 2 choses :
    - les 3 premières lignes sont des déclarations de variables qui ne sont jamais utilisées, donc tu peux sans doute les supprimer
    - Tu manipules l'objet Feuille sans l'avoir initialisé (New), donc ça ne risque pas de marcher... en supposant que ça compile, tu obtiens probablement une NullReferenceException

  3. #3
    Membre averti
    Avatar de Ogotcha
    Inscrit en
    Juillet 2008
    Messages
    232
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations forums :
    Inscription : Juillet 2008
    Messages : 232
    Points : 398
    Points
    398
    Par défaut
    Le code qu'il a mis la c'est le code de sa macro sous excel.

    Mais je vois pas ce qu'il veut faire....

    Tu souhaite mettre en forme une feuille d'un classeur excel par vb net ? je vois pas trop l'utilité a moins que derrière tu travail de ton application vb net sur ton fichier excel
    Mon Blog
    FAQs DotNet
    Fonction utile : Recherche

Discussions similaires

  1. Réponses: 2
    Dernier message: 31/12/2009, 03h06
  2. import excel 2007 dans SQL 2005 et comparaison sur 2 tables
    Par fredfleu dans le forum Développement
    Réponses: 0
    Dernier message: 23/07/2009, 14h10
  3. utlisation d'une dll unmanaged dans c++.net 2005
    Par WELCOMSMAIL dans le forum VC++ .NET
    Réponses: 2
    Dernier message: 04/05/2007, 20h09
  4. Probleme lancement macro excel 2007
    Par nico63vb dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 27/03/2007, 13h55

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