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 6 et antérieur Discussion :

[VB6]Automation Word


Sujet :

VB 6 et antérieur

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Rédacteur
    Avatar de jacma
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    612
    Détails du profil
    Informations personnelles :
    Âge : 81
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 612
    Par défaut [VB6]Automation Word
    Bonjour

    Je reprends un ancien praticiel que j'avais réalisé il y a quelques années, et dont le projet VB6 fonctionnait très bien à l'époque (mais dont le document explicatif n'avait pas été finalisé).

    Maintenant, le code suivant me renvoit une erreur 5852 (objet non disponible) dont je n'arrive pas à trouver la cause.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    With InstanceWord.ActiveDocument.MailMerge
      DialogSortie.Show vbModal
      If strModeSortie = "DocWord" Then
        .Destination = wdSendToNewDocument
    .....
    Avant cette portion de code, j'ajoute un nouveau document qui fait référence à un document modèle (.dot) à la collection Documents.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    strCheminModWord = App.Path & "\Mailing.dot"
    Set InstanceWord = New Word.Application
    InstanceWord.Application.Documents.Add Template:=strCheminModWord
    InstanceWord.Visible = False
    Merci de vos suggestions.

  2. #2
    Membre émérite
    Inscrit en
    Septembre 2005
    Messages
    617
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 617
    Par défaut
    Tout cela a l'air correct...

    cela ne doit marcher qu'avec Word 97

    Regarde ceci:

    En ce qui concerne l'ouverture du dot c ok
    CE qui doit changer a mon avis :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Dim wrdMailMerge As Word.MailMerge
    Word.WdMailMergeDestination.wdSendToNewDocument
    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
    163
     Private Sub Button1_Click(ByVal sender As System.Object, _
           ByVal e As System.EventArgs) Handles Button1.Click
            Dim wrdSelection As Word.Selection
            Dim wrdMailMerge As Word.MailMerge
            Dim wrdMergeFields As Word.MailMergeFields
     
            Dim StrToAdd As String
     
            ' Create an instance of Word  and make it visible.
            wrdApp = CreateObject("Word.Application")
            wrdApp.Visible = True
     
            ' Add a new document.
     
            wrdDoc = wrdApp.Documents.Add()
            wrdDoc.Select()
     
            wrdSelection = wrdApp.Selection()
            wrdMailMerge = wrdDoc.MailMerge()
     
            ' Create MailMerge Data file.
            CreateMailMergeDataFile()
     
            ' Create a string and insert it in the document.
            StrToAdd = "State University" & vbCr & _
                        "Electrical Engineering Department"
            wrdSelection.ParagraphFormat.Alignment = _
                        Word.WdParagraphAlignment.wdAlignParagraphCenter
            wrdSelection.TypeText(StrToAdd)
     
            InsertLines(4)
     
            ' Insert merge data.
            wrdSelection.ParagraphFormat.Alignment = _
                        Word.WdParagraphAlignment.wdAlignParagraphLeft
            wrdMergeFields = wrdMailMerge.Fields()
            wrdMergeFields.Add(wrdSelection.Range, "FirstName")
            wrdSelection.TypeText(" ")
            wrdMergeFields.Add(wrdSelection.Range, "LastName")
            wrdSelection.TypeParagraph()
     
            wrdMergeFields.Add(wrdSelection.Range, "Address")
            wrdSelection.TypeParagraph()
            wrdMergeFields.Add(wrdSelection.Range, "CityStateZip")
     
            InsertLines(2)
     
            ' Right justify the line and insert a date field
            ' with the current date.
            wrdSelection.ParagraphFormat.Alignment = _
                   Word.WdParagraphAlignment.wdAlignParagraphRight
            wrdSelection.InsertDateTime( _
                  DateTimeFormat:="dddd, MMMM dd, yyyy", _
                  InsertAsField:=False)
     
            InsertLines(2)
     
            ' Justify the rest of the document.
            wrdSelection.ParagraphFormat.Alignment = _
                   Word.WdParagraphAlignment.wdAlignParagraphJustify
     
            wrdSelection.TypeText("Dear ")
            wrdMergeFields.Add(wrdSelection.Range, "FirstName")
            wrdSelection.TypeText(",")
            InsertLines(2)
     
            ' Create a string and insert it into the document.
            StrToAdd = "Thank you for your recent request for next " & _
                "semester's class schedule for the Electrical " & _
                "Engineering Department. Enclosed with this " & _
                "letter is a booklet containing all the classes " & _
                "offered next semester at State University.  " & _
                "Several new classes will be offered in the " & _
                "Electrical Engineering Department next semester.  " & _
                "These classes are listed below."
            wrdSelection.TypeText(StrToAdd)
     
            InsertLines(2)
     
            ' Insert a new table with 9 rows and 4 columns.
            wrdDoc.Tables.Add(wrdSelection.Range, NumRows:=9, _
                 NumColumns:=4)
     
            With wrdDoc.Tables.Item(1)
                ' Set the column widths.
                .Columns.Item(1).SetWidth(51, Word.WdRulerStyle.wdAdjustNone)
                .Columns.Item(2).SetWidth(170, Word.WdRulerStyle.wdAdjustNone)
                .Columns.Item(3).SetWidth(100, Word.WdRulerStyle.wdAdjustNone)
                .Columns.Item(4).SetWidth(111, Word.WdRulerStyle.wdAdjustNone)
                ' Set the shading on the first row to light gray.
                .Rows.Item(1).Cells.Shading.BackgroundPatternColorIndex = _
                 Word.WdColorIndex.wdGray25
                ' Bold the first row.
                .Rows.Item(1).Range.Bold = True
                ' Center the text in Cell (1,1).
                .Cell(1, 1).Range.Paragraphs.Alignment = _
                          Word.WdParagraphAlignment.wdAlignParagraphCenter
     
                ' Fill each row of the table with data.
                FillRow(wrdDoc, 1, "Class Number", "Class Name", "Class Time", _
                   "Instructor")
                FillRow(wrdDoc, 2, "EE220", "Introduction to Electronics II", _
                          "1:00-2:00 M,W,F", "Dr. Jensen")
                FillRow(wrdDoc, 3, "EE230", "Electromagnetic Field Theory I", _
                          "10:00-11:30 T,T", "Dr. Crump")
                FillRow(wrdDoc, 4, "EE300", "Feedback Control Systems", _
                          "9:00-10:00 M,W,F", "Dr. Murdy")
                FillRow(wrdDoc, 5, "EE325", "Advanced Digital Design", _
                          "9:00-10:30 T,T", "Dr. Alley")
                FillRow(wrdDoc, 6, "EE350", "Advanced Communication Systems", _
                          "9:00-10:30 T,T", "Dr. Taylor")
                FillRow(wrdDoc, 7, "EE400", "Advanced Microwave Theory", _
                          "1:00-2:30 T,T", "Dr. Lee")
                FillRow(wrdDoc, 8, "EE450", "Plasma Theory", _
                          "1:00-2:00 M,W,F", "Dr. Davis")
                FillRow(wrdDoc, 9, "EE500", "Principles of VLSI Design", _
                          "3:00-4:00 M,W,F", "Dr. Ellison")
            End With
     
            ' Go to the end of the document.
            wrdApp.Selection.GoTo(Word.WdGoToItem.wdGoToLine, _
                       Word.WdGoToDirection.wdGoToLast)
     
            InsertLines(2)
     
            ' Create a string and insert it into the document.
            StrToAdd = "For additional information regarding the " & _
                       "Department of Electrical Engineering, " & _
                       "you can visit our Web site at "
            wrdSelection.TypeText(StrToAdd)
            ' Insert a hyperlink to the Web page.
            wrdSelection.Hyperlinks.Add(Anchor:=wrdSelection.Range, _
               Address:="http://www.ee.stateu.tld")
            ' Create a string and insert it in the document.
            StrToAdd = ".  Thank you for your interest in the classes " & _
                       "offered in the Department of Electrical " & _
                       "Engineering.  If you have any other questions, " & _
                       "please feel free to give us a call at " & _
                       "555-1212." & vbCr & vbCr & _
                       "Sincerely," & vbCr & vbCr & _
                       "Kathryn M. Hinsch" & vbCr & _
                       "Department of Electrical Engineering" & vbCr
            wrdSelection.TypeText(StrToAdd)
     
            ' Perform mail merge.
            wrdMailMerge.Destination = _
                       Word.WdMailMergeDestination.wdSendToNewDocument
            wrdMailMerge.Execute(False)
     
            ' Close the original form document.
            wrdDoc.Saved = True
            wrdDoc.Close(False)
     
            ' Release References.
            wrdSelection = Nothing
            wrdMailMerge = Nothing
            wrdMergeFields = Nothing
            wrdDoc = Nothing
            wrdApp = Nothing
     
            ' Clean up temp file.
            System.IO.File.Delete("C:\DataDoc.doc")
        End Sub
    http://support.microsoft.com/kb/q301656/

Discussions similaires

  1. Réponses: 5
    Dernier message: 26/07/2006, 23h45
  2. [MFC] - Automation Word bug
    Par Alice9 dans le forum MFC
    Réponses: 3
    Dernier message: 25/05/2005, 16h47
  3. [C#] [Automation Word] Récupérer la valeur d'une cellule
    Par Ditch dans le forum Windows Forms
    Réponses: 2
    Dernier message: 16/06/2004, 15h57
  4. Automation Word
    Par afan dans le forum MFC
    Réponses: 8
    Dernier message: 12/11/2003, 14h50
  5. [AUTOMATION WORD]Pilotage Word par Delphi
    Par Sunny dans le forum API, COM et SDKs
    Réponses: 5
    Dernier message: 05/12/2002, 17h09

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