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 :

Problème vb.net vs formule Excel


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 18
    Points
    18
    Par défaut Problème vb.net vs formule Excel
    Bonjour,
    J'essaie d'insérer une formule dans une feuille Excel et j'ai une message de type System.Runtime.InteropServices.COMException et je n'arrive pas à débuger.
    Voici mon 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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    Private Function Convertir_Excel(ByVal TempFile As String, ByVal Fichier_Excel As String, ByVal Nb_Ligne As Long, ByVal Nb_Ligne_Sommaire As Long) As Long
            On Error GoTo ErrorHandler
     
            Dim xlApp As New Excel.Application
            Dim Book As Excel.Workbook
            Dim Sheet As Excel.Worksheet
     
            xlApp.Workbooks.OpenText(TempFile, XlPlatform.xlWindows, 1, XlTextParsingType.xlDelimited,Excel.XlTextQualifier.xlTextQualifierDoubleQuote, False, True, False, False, False, False)
     
            xlApp.Visible = True
     
            If Fichier_Excel = "" Then
                xlApp.Workbooks(1).Sheets.Copy()
                xlApp.Workbooks(1).Close(False)
            Else
                xlApp.Workbooks(1).SaveAs(Fichier_Excel, XlFileFormat.xlWorkbookNormal)
            End If
     
            Kill(TempFile)
     
            xlApp.DisplayAlerts = False
     
            Book = CType(xlApp.Workbooks(1), Workbook)
            Sheet = CType(Book.Sheets(1), Worksheet)
     
    'L'erreur se fait ici :
            Sheet.Range(Sheet.Cells(6, 19), Sheet.Cells(Nb_Ligne - (1 + Nb_Ligne_Sommaire), 19)).FormulaR1C1 = "=IF(AND(RC[-6]=R[-1]C[-6],RC[-5]=R[-1]C[-5]),RC[-12]+R[-1]C,RC[-12])"
     
            With Sheet.Range(Sheet.Cells(6, 1), Sheet.Cells(Nb_Ligne - 1, 20))
                .Borders.LineStyle = XlLineStyle.xlContinuous
                .Borders.Weight = XlBorderWeight.xlThin
                .Borders.ColorIndex = XlColorIndex.xlColorIndexAutomatic
            End With
     
            Nb_Ligne = Nb_Ligne - 1
            Sheet.Cells(Nb_Ligne + 2, 5) = "TOTAL DU PAIEMENT:"
            Sheet.Cells(Nb_Ligne + 2, 5) = XlHAlign.xlHAlignCenter
            Sheet.Range(Sheet.Cells(Nb_Ligne + 2, 7)).Formula = "=sum(G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
     
            Sheet.Cells(Nb_Ligne + 2, 18) = "TOTAL"
            Sheet.Range(Sheet.Cells(Nb_Ligne + 2, 20)).Formula = "=sum(T6:T" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
            Sheet.Cells(Nb_Ligne + 4, 5) = "TOTAL - CHÈQUES"
            Sheet.Cells(Nb_Ligne + 4, 6) = "C"
            Sheet.Range(Sheet.Cells(Nb_Ligne + 4, 7)).Formula = "=sumif(F$6:F" & Nb_Ligne - Nb_Ligne_Sommaire & ",""=""&F" & Nb_Ligne + 4 & ",G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
            Sheet.Cells(Nb_Ligne + 5, 5) = "TOTAL - DÉPOTS DIRECTS"
            Sheet.Cells(Nb_Ligne + 5, 6) = "D"
            Sheet.Range(Sheet.Cells(Nb_Ligne + 5, 7)).Formula = "=sumif(F$6:F" & Nb_Ligne - Nb_Ligne_Sommaire & ",""=""&F" & Nb_Ligne + 5 & ",G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
            Sheet.Cells(Nb_Ligne + 6, 5) = "TOTAL - CHÈQUES ANNULÉS"
            Sheet.Cells(Nb_Ligne + 6, 6) = "A"
            Sheet.Range(Sheet.Cells(Nb_Ligne + 6, 7)).Formula = "=sumif(F$6:F" & Nb_Ligne - Nb_Ligne_Sommaire & ",""=""&F" & Nb_Ligne + 6 & ",G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
            Sheet.Cells(Nb_Ligne + 7, 5) = "TOTAL - ANNULATION CRÉDIT"
            Sheet.Cells(Nb_Ligne + 7, 6) = "AC"
            Sheet.Range(Sheet.Cells(Nb_Ligne + 7, 7)).Formula = "=sumif(F$6:F" & Nb_Ligne - Nb_Ligne_Sommaire & ",""=""&F" & Nb_Ligne + 7 & ",G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
            Sheet.Cells(Nb_Ligne + 8, 5) = "TOTAL - VERSEMENTS (ENCAISSEMENTS)"
            Sheet.Cells(Nb_Ligne + 8, 6) = "E"
            Sheet.Range(Sheet.Cells(Nb_Ligne + 8, 7)).Formula = "=sumif(F$6:F" & Nb_Ligne - Nb_Ligne_Sommaire & ",""=""&F" & Nb_Ligne + 8 & ",G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
     
            Mise_En_Page(xlApp, 1)
     
            xlApp.ScreenUpdating = True
     
            If Fichier_Excel <> "" Then
                xlApp.Workbooks(1).Save()
            End If
            xlApp.Visible = True
     
            Convertir_Excel = 0
            Exit Function
     
    ErrorHandler:
            Convertir_Excel = -2
            xlApp.Visible = True
            xlApp.DisplayAlerts = False
            xlApp.Quit()
     
        End Function
    Est-ce que quelqu'un aurait une idée de mon problème ???

  2. #2
    Expert éminent
    Avatar de bidou
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2002
    Messages
    3 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Transports

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 055
    Points : 7 962
    Points
    7 962
    Par défaut
    comme à aucun endroit de ton code tu n'appelle FormulaR1C1, ca ne va pas être simple de t'aider

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Juillet 2007
    Messages : 20
    Points : 18
    Points
    18
    Par défaut
    Bon ok j'ai modifié un peu mon code. C'est que j'ai essayé tellement de chose...
    Je ne sais plus trop ce que j'ai fais mais maintenant l'erreur se fait un peu plus bas dans mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Sheet.Range(Sheet.Cells(Nb_Ligne + 2, 7)).Formula = "=sum(G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
    Faut-il absolument mettre un deuxième paramètre dans le sheet.range ?

  4. #4
    Expert éminent
    Avatar de bidou
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2002
    Messages
    3 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Transports

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 055
    Points : 7 962
    Points
    7 962
    Par défaut
    déja ta ligne est mal écrite
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Sheet.Range(Sheet.Cells(Nb_Ligne + 2, 7)).Formula = "=sum(G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"
    ça s'écrit
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Sheet.Cells(Nb_Ligne + 2, 7).Formula = "=sum(G6:G" & Nb_Ligne - Nb_Ligne_Sommaire & ")"

Discussions similaires

  1. Problème de modification de formules Excel avec VBA.
    Par jayjay78 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 27/03/2010, 18h09
  2. Problème avec VB.net et macro excel
    Par chebmo90 dans le forum Windows Forms
    Réponses: 5
    Dernier message: 11/08/2009, 11h55
  3. [VB.NET] problème d'utilisation de substotal (excel via VB)
    Par Pynuch dans le forum Windows Forms
    Réponses: 4
    Dernier message: 17/11/2005, 13h53
  4. [VB.NET] problème pour piloter une appli. excel 2003
    Par Pynuch dans le forum Windows Forms
    Réponses: 13
    Dernier message: 16/11/2005, 13h02
  5. [VB.NET] Problème avec un OptionButton dans Excel 2003
    Par alfprod dans le forum Windows Forms
    Réponses: 3
    Dernier message: 09/09/2004, 13h40

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