Error 462...plzzzz

ILIVEAGAIN2001

New Member
Joined
Jan 24, 2010
Messages
3
Good Afternoon ,
I have the following macro code that I've been unable to resolve a particular run-time error. The macro is called from Excel 2007, takes an Excel worksheet to be used as a Word 2007 document.
I want to generate simply a list.
The macro does work sometimes. When I say sometimes, it's literally about 50% of the time!
When the macro fails, it causes a run-time error of 426. The VBA help does not do much for me as I can't figure out why it would work sometimes, and not others...
Here's the macro code:



Sub esporta2()

Dim Wrd As Word.Application
Dim Doc As Word.Document

Set Wrd = CreateObject("Word.Application", "Roberto")
Wrd.Visible = True

i = 2
j = 1
Do While Cells(i, j).Value <> ""
i = i + 1
Loop
i = i - 1

Set Doc = Wrd.Documents.Open("C:\Prova\Word.doc")
Doc.Bookmarks("Inizio").Select
Range(Cells(2, 1), Cells(i, 4)).Select
Selection.Copy


Wrd.Selection.Font.Name = "Arial"
Wrd.Selection.Font.Size = 8
Wrd.Selection.Font.Underline = wdUnderlineNone
Wrd.Selection.Font.Bold = False

Wrd.Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(14), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces

Wrd.Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(15.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces

Wrd.Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces

Wrd.Selection.PasteAndFormat (wdFormatPlainText)
Cells(2, 8).Select
Selection.Copy

Doc.Bookmarks("Nomecliente").Select

Wrd.Selection.PasteAndFormat (wdFormatPlainText)

Cells(3, 8).Select
Selection.Copy
Doc.Bookmarks("Indirizzo").Select
Wrd.Selection.PasteAndFormat (wdFormatPlainText)

Cells(4, 8).Select
Selection.Copy
Doc.Bookmarks("cap").Select
Wrd.Selection.PasteAndFormat (wdFormatPlainText)

Cells(5, 8).Select
Selection.Copy
Doc.Bookmarks("Città").Select
Wrd.Selection.PasteAndFormat (wdFormatPlainText)

Cells(6, 8).Select
Selection.Copy
Doc.Bookmarks("pv").Select
Wrd.Selection.PasteAndFormat (wdFormatPlainText)

Cells(15, 9).Select
Selection.Copy
Doc.Bookmarks("Nettomateriali").Select
Wrd.Selection.PasteAndFormat (wdFormatPlainText)

Doc.SaveAs Filename:="OFFERTA.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
End Sub



The run-time error occurs at the following line:

Wrd.Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(14), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Wrd.Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(15.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Wrd.Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces


When I bring up the help for the run-time error, it's pretty vague
Hoping someone can help me solve this problem

THANKSSSSSSS
<!-- / message -->
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,216,082
Messages
6,128,702
Members
449,464
Latest member
againofsoul

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