0% found this document useful (0 votes)
15 views

lllisp Excel selected range

The document is a forum thread discussing how to retrieve values from a selected range of cells in Excel using Visual LISP programming. A user seeks help on how to get a list of cell values from a user-selected range, and various responses provide code snippets and guidance on accessing Excel's ActiveX properties. The thread includes troubleshooting advice and code modifications to achieve the desired functionality.

Uploaded by

AMANUALE D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

lllisp Excel selected range

The document is a forum thread discussing how to retrieve values from a selected range of cells in Excel using Visual LISP programming. A user seeks help on how to get a list of cell values from a user-selected range, and various responses provide code snippets and guidance on accessing Excel's ActiveX properties. The thread includes troubleshooting advice and code modifications to achieve the desired functionality.

Uploaded by

AMANUALE D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2/4/24, 7:22 PM Excel selected range

JOBS | BLAUGI | LOG IN JOIN AUGI

Wish List Forums Get Connected Articles Publications Products About AUGI

FAQ Forum Actions Quick Links

Forum Discussions and Support Programming AutoLISP Excel selected range

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post:
click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection
below.

Results 1 to 10 of 12 Page 1 of 2 1 2 Last

Thread: Excel selected range


Thread Tools Display

2011-09-04, 03:22 PM #1

carmine.iannotta342739
Excel selected range Login to
Member Give a
Good afternoon, i'm new in visual lisp programming, so i bone
Join Date: 2011-09 hope someone can help me.
Posts: 5 Is it possible to get a list with the values of cells in a range
selected by the user? 0

Reply With Quote

2011-09-04, 03:33 PM #2

Lee Mac
Re: Excel selected range Login to
I could stop if I wanted to Give a
This should help you: bone
Join Date: 2009-03
Location: London, England http://web2.iadfw.net/terrycad/LISP/GetExcel.lsp
Posts: 304 0

Reply With Quote

2011-09-06, 06:36 AM #3

carmine.iannotta342739
Re: Excel selected range Login to
Member Give a
bone

https://forums.augi.com/showthread.php?132825-Excel-selected-range&s=d033238e96fda1d207cd6c8f5eb8610a&p=1150815#post1150815 1/6
2/4/24, 7:22 PM Excel selected range

Join Date: 2011-09 Thank you Lee Mac, but in this code i need to specify the
Posts: 5 cell. Is there a way to get the cell selected in excel?
0

Reply With Quote

2011-09-06, 01:50 PM #4

irneb
Re: Excel selected range Login to
Certifiable AUGI Addict Give a
You need to look at the Excel ActiveX reference: bone
Join Date: 2015-11 http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx
Location: Jo'burg SA
Posts: 4,512 From there you should be able to browse to the relevant 0
propery/object. E.g. from the Application object you get
the ActiveCell property, which contains a Range object.
This in turn either has an Address string or a Cells object
(i.e. column number & row number) - whichever you need.

I preferred showing you how to get there, so you can get


at other items as well.

Reply With Quote

2011-11-16, 07:58 AM #5

carmine.iannotta342739
Re: Excel selected range Login to
Member Give a
This is what i did until now: bone
Join Date: 2011-09
Posts: 5 Code:
(defun c:proex()
0
(vl-load-com)
(setq documento (getfiled "esplora" "esempi
(setq excel (vlax-create-object "Excel.Appl
(setq fogliolavoro (vlax-get-property excel
(setq attfoglio (vlax-invoke-method fogliol
(vla-put-visible excel :vlax-true)
(getint )
(setq selezione (vlax-get-property excel 'S
(print selezione)

But when i use it he gives me something like:


#<VLA-OBJECT Range 0000000036f66178>

What's wrong?
I need to store the values ​in the range in a list, how can I
go on?

Reply With Quote

2011-11-16, 09:53 AM #6

irneb
Re: Excel selected range Login to
Certifiable AUGI Addict Give a
bone
Originally Posted by carmine.iannotta342739

https://forums.augi.com/showthread.php?132825-Excel-selected-range&s=d033238e96fda1d207cd6c8f5eb8610a&p=1150815#post1150815 2/6
2/4/24, 7:22 PM Excel selected range

Join Date: 2015-11


But when i use it he gives me something like:
Location: Jo'burg SA #<VLA-OBJECT Range 0000000036f66178>
Posts: 4,512 0
What's wrong?
I need to store the values ​in the range in a list, how
can I go on?

Nothings wrong at all. You would just want to go further.

You get the current selection inside Excel. That is a range


of cells (i.e. something like B3 ... H16). Notice the
returned value: #<VLA-OBJECT Range
0000000036f66178>

So you now have a reference to the Range Object. Thus


you need to check how many cells are selected and step
through each to find its value. Notice the Range Object's
Properties: There's an Item and a Count property which
you'd probably need to use to get hold of a list of "Cell"
Objects - which are actually Range Objects in themselves -
but addressing only one single cell.

If the range object's count property = 1, then you should


be able to get the value contained inside the cell using the
Range Object's Value property.

Reply With Quote

2011-11-16, 10:50 AM #7

irneb
Re: Excel selected range Login to
Certifiable AUGI Addict Give a
As an example I've modified your code a bit (marked in bone
Join Date: 2015-11 red):
Location: Jo'burg SA Code:
Posts: 4,512
(defun c:proex (/ documento excel fogliolavor
0
(vl-load-com)
(setq documento (getfiled "esplora" "esempi
(setq excel (vlax-get-or-create-object "Exc
(setq fogliolavoro (vlax-get-property excel
(setq attfoglio (vlax-invoke-method fogliol
(vla-put-visible excel :vlax-true)
(getint)
(setq selezione (vlax-get-property excel 'S
(vlax-for row (vlax-get-property selezione
(setq row-list nil) ;Initialize the tempo
(vlax-for cell (vlax-get-property row 'Co
(setq row-list (cons (vlax-get cell 'Va
)
(setq values-list (cons (reverse row-list
)
(vlax-release-object excel) ;Release the re
(reverse values-list) ;Return the list of v

Notice I've also localized the variables, this is a thing


which I'd highly advise you do on all your routines.

And above all, release any ActiveX objects you've created


through vlax-create-object / vlax-get-or-create-object.

https://forums.augi.com/showthread.php?132825-Excel-selected-range&s=d033238e96fda1d207cd6c8f5eb8610a&p=1150815#post1150815 3/6
2/4/24, 7:22 PM Excel selected range
Else you could run out of RAM quite quickly, not to mention
You might also want to close Excel before releasing the obje

Reply With Quote

2011-11-16, 02:15 PM #8

carmine.iannotta342739
Re: Excel selected range Login to
Member Give a
This is exactly what I need, thank irneb! bone
Join Date: 2011-09
Posts: 5
0

Reply With Quote

2011-11-17, 05:56 AM #9

irneb
Re: Excel selected range Login to
Certifiable AUGI Addict Give a
bone
Join Date: 2015-11 Originally Posted by carmine.iannotta342739
Location: Jo'burg SA This is exactly what I need, thank irneb!
Posts: 4,512 0
You're welcome

There's many ways of doing this, I'm not too sure how it
would perform if you've got multiple ranges selected in
excel - i.e. If you hold down the Ctrl key and select 2 or
more areas. From my tests it seems to work fine for 2
separate portions on the same sheet, but ends up with nil
values if you've selected across sheets.

BTW, why did your code use 13 in the getfiled call? I'd
think 12 would be more "correct":
1 = Ask for new file name, if exists ask user if they
want to overwrite. (I don't agree with this one)
+
4 = Allow other extensions than the one specified.
+
8 = Search for the file in the support paths if not
specified as full path.

Reply With Quote

2011-11-20, 05:52 AM #10

fixo
Re: Excel selected range Login to
AUGI Addict Give a
You might be want to look at to do it bone
by Excel way using Input function:
(from my oldies so sorry for bad code manner)
Code: 0
Join Date: 2005-05
;; local defun
(defun RefSelection (/ *error* addr c2 c2 Exc
Location: Pietari, Venäjä (vl-load-com)
(defun *error* (msg)
https://forums.augi.com/showthread.php?132825-Excel-selected-range&s=d033238e96fda1d207cd6c8f5eb8610a&p=1150815#post1150815 4/6
2/4/24, 7:22 PM Excel selected range
Posts: 1,269 (if
(vl-position
msg
'("console break"
"Function cancelled"
"quit / exit abort"
)
)
(princ "Error!")
(princ msg)
)
(vl-catch-all-apply
'vlax-invoke-method
(list Wbk "Close")
)

(vl-catch-all-apply
'vlax-invoke-method
(list ExcelApp "Quit")
)
(mapcar
(function (lambda (x)(vl-catch-all-apply(
(if ( t ( l bj t l

Reply With Quote

Page 1 of 2 1 2 Last

« Previous Thread | Next Thread »

Forum Discussions and Support Programming AutoLISP Excel selected range

Similar Threads
Get Excel range names in lisp Replies: 4
By marian.italian356732 in forum AutoLISP Last Post: 2013-02-25, 09:49 PM

Show Selected Workset(s) in selected views - is it possible? Replies: 4


By ReachAndre in forum BIM Management - General Last Post: 2012-08-29, 12:11 PM

I want to Export the Selected Text and Mtext to Excel Replies: 4


By avinash00002002 in forum VBA/COM Interop Last Post: 2011-03-31, 02:19 PM

When Conduit is selected, properties pallete shows nothing selected Replies: 3


By rmccarty in forum AMEP General Last Post: 2010-03-01, 06:23 PM

"Nothing Selected" message when Objects are Selected Replies: 4


By mark.81576 in forum AutoCAD General Last Post: 2007-04-13, 05:00 PM

Posting Permissions
You may not post new threads BB code is On
You may not post replies Smilies are On
You may not post attachments [IMG] code is On
You may not edit your posts [VIDEO] code is On
HTML code is Off

Forum Rules

https://forums.augi.com/showthread.php?132825-Excel-selected-range&s=d033238e96fda1d207cd6c8f5eb8610a&p=1150815#post1150815 5/6
2/4/24, 7:22 PM Excel selected range

Powered by vBulletin® Version 4.2.5     


Copyright © 2024 vBulletin Solutions Inc. All rights
reserved.
Sponsors | Benefactors | Advertising | Terms of Service
| Privacy Policy | Sitemap | Contact
©1990-2024 AUGI, Inc.
All Rights Reserved. Reproduction or copying of
images is prohibited.
All times are GMT. The time now is 04:17 PM.

https://forums.augi.com/showthread.php?132825-Excel-selected-range&s=d033238e96fda1d207cd6c8f5eb8610a&p=1150815#post1150815 6/6

You might also like