Setting an active cell in Excel from Autocad

Setting an active cell in Excel from Autocad

Anonymous
Not applicable
1,273 Views
5 Replies
Message 1 of 6

Setting an active cell in Excel from Autocad

Anonymous
Not applicable
I've tried every which way to execute this Excel VBA code from Autocad VBA program but nothing works. This code works when I do it from Excel:

Range(Cells(1, 1), Cells(1, 1)).Activate

so when I use this code in Acad VBA, it doesn't work
Set excelApp = GetObject(, "Excel.Application")
excelApp.Range(Cells(1, 1), (1, 1)).Activate

Also I need to use the the numbers (1, 1) instead of ex. $A$1
0 Likes
1,274 Views
5 Replies
Replies (5)
Message 2 of 6

fxcastil
Advocate
Advocate
see link and attachment test.zip in link below for connectting to excel . Also search this group for "Excel" , this topic covered many times

http://discussion.autodesk.com/thread.jspa?threadID=448847

Reply From: maxima10
Date: Jan/13/06 - 00:18 (GMT)

Re: Couldn't Be More Stumped Finding A Specific Row
stck2mlon

More than one previous post already answered you question about finding a value in a row.
see attched for using for next loop and the used range property. Just modify this with
If objSheet.Cells(indx, 1) = "What I am looking for" then

Not to offend you but consider purchasing a book on Excel
Excel 2000 power programming With VBA
By John Walkenbach

Maximo

[Attachment: Test.zip]


Fred C
0 Likes
Message 3 of 6

Anonymous
Not applicable
First, thanks for the reply, I appreciate all input. Second, not offended, but I do have several books on VB and VBA, know any that deal with issuing Excel methods from Acad VBA? I could use one like that.
Sorry, but I think my point was missed, I can get values from cells and bring to Acad and vise versa. What I'm tring to do is change which cell is the active cell in a wrksht. As I said in my first post, I can do this when I'm coding in Excel VBA but not in Acad VBA. Thanks in advance.
0 Likes
Message 4 of 6

Anonymous
Not applicable
you need to activate the sheet, try this

Set excelApp = GetObject(, "Excel.Application")
excelApp.Worksheets("Sheet1").Activate
Set excelSheet = excelApp.ActiveWorkbook.Sheets("Sheet1")
excelSheet.Range(Cells(1, 1), (1, 1)).Activate
0 Likes
Message 5 of 6

fxcastil
Advocate
Advocate
The reply was from a previous post . I was giving you the link to download the sample attached file.

As for your question once you add a reference to the Excel library within AutoCad you should in theory have acess to all the same Excel object model in AutoCAD. If you use the object browser in AutoCAD to view the Excel library you see the complete Excel object model. BUT I have found a couple of things that worked differently in AutoCAD.

instead of Range(Cells(1, 1), Cells(1, 1)).Activate
try cells (1,1).activate

so when I use this code in Acad VBA, it doesn't work
Set excelApp = GetObject(, "Excel.Application")
' make sure you activate desired sheet first
excelApp.Cells(1, 1).Activate

Fred C
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks to all for responding! With your replies, I found that I wasn't getting the sheet, and I needed to get not a named file but what was the last active Excel session, so here's what finally worked.

Set excelApp = GetObject(, "Excel.Application")
sheetname = excelApp.ActiveSheet.Name
Set shtObj = excelApp.Worksheets(sheetname)
shtObj.Cells(1, 1).Activate
0 Likes