# Visual Basic > Office Development >  Error 462 at the second execution

## Flappy

Hi all, 

I'm currently writing a macro filling a Word file with data comming from my Excel document.
At a moment I select a range in Excel and paste it as table in Word then I arrange the style of the table.

During the first usage of my macro, everything goes well. When I try to re-execute the macro, I always get the error 462 about the remote server.
I already spend a lot of time searching what could be the reason, I have the feeling that's because I'm not explicit enough. I tried to be more explicit but without success.

The problem occurs on the line 17.


```
 oTbl.Rows.SetHeight RowHeight:=CentimetersToPoints(0.53), _
    HeightRule:=wdRowHeightExactly
```

If someone has an idea on what is wrong with my code, please shoot  :Smilie: 




```
Private Sub Ecriture_Tableau_description(doc_target As Word.Document, NomSignet As String, langue As String)
 
    Dim oTbl As Table
 
    doc_target.Bookmarks(NomSignet).Select
    doc_target.Bookmarks(NomSignet).Range.PasteSpecial
    doc_target.Tables(2).AllowAutoFit = True
    doc_target.Tables(2).AllowPageBreaks = False
   ' doc_target.Tables(2).Rows.WrapAroundText = True
 
 
    Set oTbl = doc_target.Tables(2)              'on met le tableau 2 dans l'objet oTabl
 
    'ajout d'une ligne au dessus
    oTbl.Rows.Add (oTbl.Rows(1))
   'on met la hauteur de ligne à 0.53 cm
    oTbl.Rows.SetHeight RowHeight:=CentimetersToPoints(0.53), _
    HeightRule:=wdRowHeightExactly
 
 
 
    oTbl.PreferredWidthType = wdPreferredWidthPoints
    oTbl.PreferredWidth = CentimetersToPoints(16.6) 'on met la largeur du tab à 16.6 cm
 
    'Insertion des noms des colonnes:
     If langue = "Deutsch" Then
        oTbl.Cell(1, 1).Range.Text = "Beschreibung"
        oTbl.Cell(1, 3).Range.Text = "Betrag"
        oTbl.Cell(1, 4).Range.Text = "TVA"
    ElseIf langue = "Französich" Then
        oTbl.Cell(1, 1).Range.Text = "Description"
        oTbl.Cell(1, 3).Range.Text = "Montant"
        oTbl.Cell(1, 4).Range.Text = "TVA"
    Else
        MsgBox ("Paramètre de langue non trouvé")
    End If
 
oTbl.Cell(1, 3).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
oTbl.Cell(1, 4).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
 
    ' mise en forme : contopur en ligne simple verte
    With oTbl.Borders(wdBorderLeft)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth100pt
        .Color = -704577690
    End With
    With oTbl.Borders(wdBorderRight)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth100pt
        .Color = -704577690
    End With
    With oTbl.Borders(wdBorderTop)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth100pt
        .Color = -704577690
    End With
    With oTbl.Borders(wdBorderBottom)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth100pt
        .Color = -704577690
    End With
 
    ' régalge de la largeur des colonne
 
 
    oTbl.Columns(1).PreferredWidthType = wdPreferredWidthPoints
    oTbl.Columns(1).PreferredWidth = CentimetersToPoints(3.46)
    oTbl.Columns(2).PreferredWidthType = wdPreferredWidthPoints
    oTbl.Columns(2).PreferredWidth = CentimetersToPoints(7.58)
    oTbl.Columns(3).PreferredWidthType = wdPreferredWidthPoints
    oTbl.Columns(3).PreferredWidth = CentimetersToPoints(3.46)
    oTbl.Columns(4).PreferredWidthType = wdPreferredWidthPoints
    oTbl.Columns(4).PreferredWidth = CentimetersToPoints(2.12)
 
    'réglage de la première ligne
    With oTbl.Rows(1).Range.Font
        .TextColor = wdColorWhite
        .Size = 12
        .Bold = True
    End With
    oTbl.Rows(1).Range.Shading.BackgroundPatternColor = -704577690
 
   'ajout des lignes vertes au dessus des cellules non vides de la première colonnes
   For i = 1 To oTbl.Rows.Count
            'If oTbl.Cell(i, 1).Range.Text <> "" Then
            If Len(oTbl.Cell(i, 1).Range.Text) > 2 Then
               With oTbl.Rows(i).Borders(wdBorderTop)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth100pt
                    .Color = -704577690
                End With
 
            End If
    Next i
 
    Set oTbl = Nothing
 
 
 
End Sub
```

----------


## Dan_W

Which application are you running the code from - Excel or Word? 

When you're working across applications, it's important to make sure that you are clear to qualify which Application data type you're trying to use (qualify = specify). So, like you did at the start, in the argument, you've written *doc_target As Word.Document* you should specify other Word data types with the express qualification - *Word.* Often times, when it comes to working across Excel and Word, errors will almost always arise from the code declaring a variable with Range data type. This is hugely problematic because while both Word and Excel use Range as a data type, they refer to wildly different things.

Here, you've used: *Dim oTbl As Table*. While a 'table' in Excel is a ListObject data type, and it doesn't have a corresponding 'table' which which to be confused,after  looking your error number/description, it seems to arise when you've not qualified the relevant Application. Assuming that you've set a reference to the Word Object Library, try changing *Table* to *Word.Table*

I don't know if it definitely is going to solve the problem (frankly, I would've thought it would break on the line above), but it will certainly help.

----------


## Flappy

Hi Dan, 

Many thanks for your reply and the explanation.
The code is running from Excel. 
I tried to replace Table by Word.Table, the result is the same, an error when running the code for the second time.
I'll continue to search and pass over my code to check if there are other part that I need to modify in the same way.

----------


## Dan_W

> Hi Dan, 
> 
> Many thanks for your reply and the explanation.
> The code is running from Excel. 
> I tried to replace Table by Word.Table, the result is the same, an error when running the code for the second time.
> I'll continue to search and pass over my code to check if there are other part that I need to modify in the same way.


Ahh - it's probably CentimetersToPoints, actually. That's a method of the Word object, so try *Word.CentimetersToPoints*. I note that you've used a few times throughout the code. Fingers crossed.

----------


## Flappy

Hi, 

Indeed I use this method few times in the code and in another sub as well. I added the Word. for all of them (in the whole project) and I got any changes  :Frown: 
I also added the Word. to the other word method or properties that I have in the projects. I also checked that I'm correctly set the object to nothing at the exit of the code.

I noticed another point. After a crash with the error 462, the usage of the stop button allows me reuse the macro without any problems. 
I don't know the exact action of the button, I assume it flushs the memory used by the VBA execution. So it seems that I have somewhere a confusion with the objects between Word and Excel. In that case maybe it's elsewhere in the project outside of this function.

----------

