Error when adding table to Word from Excel VBA

alx1056

New Member
Joined
Jul 11, 2018
Messages
8
Hello,

I recently was able to fix my code by adding a table to Word From Excel with VBA However now if I want to add 2 or more tables then it gives me the Error " Run Time Error 462: The remote server machine does not exist when working with WORD via Excel VBA "

I am not sure how to fix this?

Code:

Code:
Option Explicit

Sub CreateWordDoc()
Dim wdApp As New Word.Application, wdDoc As Word.Document, wdRng As Word.Range
Dim myCat As Long: myCat = InputBox("Enter your Category: ")
    
With wdApp
  .Visible = True
  Set wdDoc = .Documents.Add
  With wdDoc.Range
    .PageSetup.TopMargin = InchesToPoints(0.3)
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Font.Bold = True
    .Font.Underline = True
    .InsertAfter "FY 19 CAT " & myCat
    .InsertParagraphAfter
    Set wdRng = .Characters.Last
    With wdRng
      .ParagraphFormat.Alignment = wdAlignParagraphLeft
      .ParagraphFormat.LeftIndent = InchesToPoints(-0.7)
      .ParagraphFormat.SpaceAfter = 5
      .Font.Underline = False
      .Font.Size = 11
      .InsertParagraphAfter
      .InsertAfter ("Grade Number:")
      .InsertParagraphAfter
      .InsertAfter ("Config #:")
      .InsertParagraphAfter
      .InsertAfter ("Grade Name:")
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Dept:")
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Class/Subclass:")
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Season Code:")
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "TimeFrame:")
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Grade Type:")
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Index Breakpoint Bands by Volume Grade:")
      .InsertParagraphAfter
      .InsertBreak Type:=wdLineBreak
      Worksheets("Sheet2").Range("K1", "Q2").Copy
      .Paste
      .Tables(1).Rows.Alignment = wdAlignRowCenter
      .InsertParagraphAfter
      .Collapse wdCollapseEnd
      .InsertParagraphAfter
      .InsertBreak Type:=wdLineBreak
      .Collapse wdCollapseEnd
      Worksheets("Sheet2").Range("A1", "B4").Copy
      .Paste
      .Tables(2).Rows.Alignment = wdAlignRowCenter
      
    End With
  End With
End With
End Sub
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,215,771
Messages
6,126,799
Members
449,337
Latest member
BBV123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top