VBA Runtime Error 5843

  • Thread starter rosano.silveira
  • Start date
R

rosano.silveira

I'm kinda a newbie to Word VBA. I generated a macro for removing
right, top, bottom borders of a cell frm a table. But when i try to
run the macro after modifying the code to run for multiple cells. I
gives an error msg

Run-Time Error 5843: One of the values passed to this method or
property is out of range.


With Selection.Cells
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleOutset
.LineWidth = wdLineWidth075pt ---> Errors out on this line
.Color = wdColorAutomatic
End With
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleOutset
.DefaultBorderLineWidth = wdLineWidth075pt
.DefaultBorderColor = wdColorAutomatic
End With


Any advice on this would help. Thanks.
 
G

Greg Maxey

I didn't see your error, but then I might not understand what you are
trying to do:

Try:

Sub Scratchmacro()
Dim oCell As Word.Cell
For Each oCell In Selection.Cells
With oCell
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleOutset
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
'.Borders.Shadow = False 'This line does not appply to cells.
End With
Next oCell
With Options
.DefaultBorderLineStyle = wdLineStyleOutset
.DefaultBorderLineWidth = wdLineWidth075pt
.DefaultBorderColor = wdColorAutomatic
End With
End Sub
 
R

R-ESQR

Tried the code, i get the same error on .LineWidth, Am I missing
somthing here?

Rosano
 
G

Greg Maxey

I don't know what you might be missing. I ran the code in Word2003 and
Word2007 with no errors.

You can send me your document (don't send macros, but your code in the
document text) and I will have a look.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top