Run Time Error 462 when copying and pasting Tables VBA

alx1056

New Member
Joined
Jul 11, 2018
Messages
8
Hello,


I am having an issue with my code, I am trying to copy 3 different locations within Excel and then Paste those values/tables within Word.


I keep getting a Run Time Error of 426. I tried looking up what this could mean but I am having no luck.


I have been driving myself crazy trying to fix it but I cannot!


Please anyone that knows how to copy and paste tables with user input.


My Code:

Code:
Sub TalkToWord()
Dim wdApp As New Word.Application, wdDoc As Word.Document, wdRng As Word.Range
Dim myCat As Integer: myCat = InputBox("Enter your Category: ")
Dim myConfig As Long: myConfig = InputBox("Enter your Config #: ")
Dim myGradeName As String: myGradeName = InputBox("Enter your Grade Name: ")
Dim myDept As Integer: myDept = InputBox("Enter your Dept: ")
Dim myClass As Integer: myClass = InputBox("Enter your Class/Subclass: ")
Dim mySeason As String: mySeason = InputBox("Enter your Season Code: ")
myTimeFrame = Application.InputBox("Enter your Time Frame: ", FormatDateTime(Date, vbShortDate))
    
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 = 12
      .InsertParagraphAfter
      .InsertAfter ("Grade Number:")
      .InsertParagraphAfter
      .InsertAfter ("Config #:")
      .InsertParagraphAfter
      .InsertAfter ("Grade Name:" & myGradeName)
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Dept:" & myDept)
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Class/Subclass:" & myClass)
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Season Code:" & mySeason)
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "TimeFrame:" & myTimeFrame)
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Grade Type:" & myGradeType)
      .InsertParagraphAfter
      .InsertAfter (Chr(9) & "-" & "Index Breakpoint Bands by Volume Grade:")
      .InsertParagraphAfter
      .InsertParagraphAfter
      .Collapse wdCollapseEnd
      .InsertParagraphAfter
      .InsertBreak Type:=wdLineBreak
      .Collapse wdCollapseEnd
      .PageSetup.TopMargin = InchesToPoints(0.1)
      Worksheets("Sheet2").Range("A1", "B2").Copy
      .Paste
      .Tables(1).Rows.Alignment = wdAlignRowCenter
      .InsertBreak Type:=wdLineBreak
      .Collapse wdCollapseEnd
      .PageSetup.TopMargin = InchesToPoints(0.1)
      Worksheets("Sheet2").Range("K1", "Q2").Copy
      .Paste
      .Tables(2).Rows.Alignment = wdAlignRowCenter
      .InsertBreak Type:=wdLineBreak
      .Collapse wdCollapseEnd
      .PageSetup.TopMargin = InchesToPoints(0.1)
      Worksheets("Sheet2").Range("K4", "Q6").Copy
      .Paste
      .Tables(3).Rows.Alignment = wdAlignRowCenter
    End With
  End With
End With
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,534
Messages
6,120,086
Members
448,944
Latest member
sharmarick

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