Thread: Error no. 1004
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Cyrus[_2_] Cyrus[_2_] is offline
external usenet poster
 
Posts: 1
Default Error no. 1004

HI,

I am using the sample code below to draw borders in

excel sheet from MSAccess Form.

'---------------------------------------------------------------------------
----------------------------------

Dim objXL As Excel.Application

Dim objWkb As workbook

Dim objSht As Worksheet

Set objXL = Nothing

Set objWkb = Nothing

Set objSht = Nothing

'creating new excel object

Set objXL = New Excel.Application

Set objWkb = objXL.Workbooks.Add

Set objSht = objWkb.Worksheets(1)



Range("B" & Val(lngrow + 5) & ":AE" & Val(lngrow +

32)).Select

Selection.Borders(xlDiagonalDown).LineStyle =

xlNone

Selection.Borders(xlDiagonalUp).LineStyle = xlNone

With Selection.Borders(xlEdgeLeft)

..LineStyle = xlContinuous

..Weight = xlThin

..ColorIndex = xlAutomatic

End With

With Selection.Borders(xlEdgeTop)

..LineStyle = xlContinuous

..Weight = xlThin

..ColorIndex = xlAutomatic

End With

With Selection.Borders(xlEdgeBottom)

..LineStyle = xlContinuous

..Weight = xlThin

..ColorIndex = xlAutomatic

End With

With Selection.Borders(xlEdgeRight)

..LineStyle = xlContinuous

..Weight = xlThin

..ColorIndex = xlAutomatic

End With

Selection.Borders(xlInsideVertical).LineStyle =

xlNone

Selection.Borders(xlInsideHorizontal).LineStyle =

xlNone

'---------------------------------------------------------------------------
---------------------------------

I get the borders first time, when i run next time i

am not getting borders and error occurs. but if i

close application and then run , then the borders

appear.

err number - 1004, range object failed something like that

Please help me.

TIA,

Cyrus