Spacepig62 Posted May 2, 2018 Posted May 2, 2018 (edited) Hello all... It's been a VERY long time since I was on this site, but I'm hoping that there a couple of hot shots still out there :-) I've been tasked with writing a program that will extract attributes from AutoCAD and export them automatically into excel, and whilst I've got the program to work I can't get it to set the active worksheet prior to pushing the info into excel. The relevant fragment of code is as follows.... (vl-load-com) (setq tlbfile (findfile "C:\\Program Files\\Microsoft Office 15\\root\\office15\\Excel.exe")) (vlax-import-type-library :tlb-filename tlbfile :methods-prefix "msxl-" :properties-prefix "msxl-" :constants-prefix "msxl-") (setq xfile "c:\\attext_test.xls") (cond ((setq fn (findfile xfile)) (cond ((setq appsession (vlax-get-or-create-object "Excel.Application")) (vlax-invoke-method (vlax-get-property appsession 'workbooks) 'open fn) (vla-put-visible appsession 0) ) ) ) (t (alert (strcat "nCannot locate source file: " xfile))) ) (setq xlapp appsession) (msxl-Activate (vla-Item (msxl-Get-WorkSheets xlapp) "Instrumentation")) (setq rng (msxl-get-activesheet xlapp)) The second line to last should set the active page as "Instrumentation" in the excel file, but it doesn't. Can anyone see what I'm doing wrong? I'll post the whole program for people to use as soon as I've got this sorted (plus the next program that pushes the info back from excel into the autocad attributes) Best regards and thanks in advance Spacepig62 Edited May 2, 2018 by SLW210 Added Code Tags Quote
dlanorh Posted May 2, 2018 Posted May 2, 2018 It's years (10+) since i did this stuff, and i hated type libraries with a passion, so avoided them. Perhaps you can adapt this code snippet for your need, I've replaced my xl_app with yours (xlapp) and inserted your sheet name into the first line (setq activeSheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property xlapp "Sheets") "Item" "Instrumentation"))) (if (not (vl-catch-all-error-p activeSheet)) ;if worksheet found (vlax-invoke-method activeSheet "Activate") ;set it as activesheet (setq activeSheet nil) ) Quote
Spacepig62 Posted May 2, 2018 Author Posted May 2, 2018 Hi dlanorh Thanks very much for your help - I'll try it tomorrow at work and all being well I'll post the full program for everyone as soon as it's all tested - like you it's been years since I've done any major programming (I've been using Revit MEP since) - I wrote the original and posted that in 2006.....where have all the years gone?!? Best regards Spacepig62 Quote
SLW210 Posted May 2, 2018 Posted May 2, 2018 Please read the Code Posting Guidelines and have your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
Grrr Posted May 2, 2018 Posted May 2, 2018 It's years (10+) since i did this stuff, and i hated type libraries with a passion, so avoided them. Just curious - why? Are there any drawbacks by using type libraries or you just hate customly-named properties/methods/events? Quote
dlanorh Posted May 3, 2018 Posted May 3, 2018 Just curious - why? Are there any drawbacks by using type libraries or you just hate customly-named properties/methods/events? The code was being used across three versions of Excel, and each version had it's own type library IIRC. I found it a nightmare :ouch: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.