help with run time Error 462 server unavailable

mrfuller

New Member
Joined
May 15, 2014
Messages
1
Hello,

I am working on a script in Excel 2007, and I keep getting error 462. Here is the entire script:

Sub ControlWord()
' You must pick Microsoft Word 8.0 from Tools>References
' in the VB editor to execute Word commands.
' See VB Help topic "Controlling One Microsoft Office Application from Another"
' for more information.
' Originally published by MrExcel.com | Excel Resources | Excel Seminars | Excel Products 2/28/1999


Dim appWD As Word.Application
' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application")
appWD.Visible = True


'Sheets("report-skipped-list-mn").Select
'Find the last row with data in the database
'FinalRow = Sheets("report-skipped-list-mn").Range("A200").End(xlUp).Row
FinalRow = Range("A200").End(xlUp).Row
'Sheets("Template").Range("A6").Value = FinalRow
For i = 2 To FinalRow

'Sheets("report-skipped-list-mn").Select

Dim LeftHeader As String
LeftHeader = Sheets("report-skipped-list-mn").Range("C" & i) & "-" & Sheets("report-skipped-list-mn").Range("D" & i) & "-" & Sheets("report-skipped-list-mn").Range("E" & i)
'Concatenate three cells into desired left side header
Dim RightHeader As String
RightHeader = "AID: " & Sheets("report-skipped-list-mn").Range("F" & i) & " | " & Date
'Put LeftHeader into A1 cell
Sheets("Template").Select
Sheets("Template").Range("A1").Value = LeftHeader
Sheets("Template").Range("H1").Value = RightHeader
'Range("A1").Paste
' Copy the data for the new document to the clipboard
Range("A1:I1").Copy
' Tell Word to create a new document
appWD.Documents.Add
' Tell Word to paste the contents of the clipboard into the new document
appWD.Selection.Paste
'Add Delimiter



'Set appWD = Nothing
appWD.Selection.MoveDown Unit:=wdLine, Count:=2
appWD.Selection.TypeParagraph
appWD.Selection.MoveUp Unit:=wdLine, Count:=1

With appWD.Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With

appWD.Selection.MoveDown Unit:=wdLine, Count:=1
appWD.Selection.TypeParagraph
' Change drive
'ChDrive "E"
' Change directory
'ChDir "E:\Documents\Chegg"
' Save the new document with a sequential file name
appWD.ActiveDocument.SaveAs Filename:=LeftHeader
' Close this new word document
appWD.ActiveDocument.Close
Next i
' Close the Word application
appWD.Quit
End Sub


I believe the problem is with the 'With' loop because when I turn those lines of code into comments, the program runs without errors. The problem is that I want the With loop to create a horizontal line across a Word document. I copied the With loop from recording a macro where I create the line by typing "---" and then hitting Enter; my AutoCorrect settings change this to the desired line. So to be clear, my questions are:

1) How can I fix the code to eliminate the error?

or

2) Is there another way I can add the horizontal line?

I would appreciate any help anyone could provide. Sorry if the formatting of the code makes it difficult to follow.

Sincerely,
Mike
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,217,156
Messages
6,134,943
Members
449,899
Latest member
stanew

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