Help with Runtime error 462

JeremySun

Board Regular
Joined
Jul 1, 2011
Messages
98
When I run the code below I'm getting a runtime error 462 and I can't find my error (other than my code is sloppy) I'm very new with VBA..

Code:
Private Sub CommandButton2_Click()
    Sheets("AHLTA").Visible = True
    Sheets("AHLTA").Select
    ActiveSheet.Cells.EntireColumn.Hidden = False
    ActiveSheet.Range("A1:I1").Select
    ActiveSheet.Range("I1").Activate
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:I50").AutoFilter Field:=8, Criteria1:= _
        xlFilterToday, Operator:=xlFilterDynamic
    ActiveSheet.Range("A1:I50").Select
    Selection.Copy
    'to make the word document
    Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("G:\Information Management (Restricted)\Training\trial\Sign In Final.doc")

With wdDoc
wdApp.Visible = True
wdApp.Selection.PasteAndFormat (wdPasteDefault)
wdApp.ActiveWindow.View.ShowXMLMarkup = wdToggle
   wdApp.ActiveDocument.ToggleFormsDesign
    wdApp.ActiveWindow.View.ShowXMLMarkup = wdToggle
    wdApp.ActiveDocument.ToggleFormsDesign
    wdApp.Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
    With ActiveDocument.PageSetup
   .Orientation = wdOrientLandscape

Set wdDoc = Nothing
Set wdApp = Nothing
End With
End With
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I have not much experience with automating Word from Excel, but at the very least, tell the helpers on what line of code you receive the error.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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