Error no. 1004

C

Cyrus

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
 
J

Jim Rech

Why don't you add a objXL.Visible = True so you can see what is happening?
When you say you run it a second time, you mean you're instantiating another
instance of Excel? If so I don't know why the second instance should be
affected by the first. If not, then you really didn't post the code you're
running which makes it harder to help you.
 

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