TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CincyJeff on December 07, 2015, 09:23:10 AM

Title: Set focus to Excel and back
Post by: CincyJeff on December 07, 2015, 09:23:10 AM
I'm working on a program that needs user input to select Excel cells so I can import data. I have Excel open and the application object but I don't know how to change program focus from lisp to Excel and back as I process a list of data. I can read the current active cell, but I can't pause the lisp to allow the user to select a different cell. Any ideas or help?
Title: Re: Set focus to Excel and back
Post by: CincyJeff on December 07, 2015, 09:57:51 AM
I've tried (vlax-invoke-method *excelapp* 'ActivateMicrosoftApp) and (vlax-invoke-method *excelapp* 'ActivateMicrosoftApp "Excel.Application") but no good so far.
Title: Re: Set focus to Excel and back
Post by: Lee Mac on December 07, 2015, 12:01:24 PM
I've not tested to determine whether what you are looking to achieve is actually possible, but my first thought would be that you could use the appactivate method (https://msdn.microsoft.com/en-us/library/wzcddbek%28v=vs.85%29.aspx) of the WSH to switch focus to Excel & back.
Title: Re: Set focus to Excel and back
Post by: CincyJeff on December 07, 2015, 01:22:24 PM
I tried
Code - Auto/Visual Lisp: [Select]
  1.       'appactivate "Microsoft Excel - Filename.xlsx")
but it doesn't pause for user input.
Am I using this correctly?
Title: Re: Set focus to Excel and back
Post by: VovKa on December 07, 2015, 04:33:54 PM
http://www.theswamp.org/index.php?topic=50465.0
Title: Re: Set focus to Excel and back
Post by: CincyJeff on December 08, 2015, 11:50:25 AM
VovKa,
That link did the trick. The getstring halts AutoCAD until you activate the Excel window, select an active cell, re-activate AutoCAD, and press enter. That just saved me a lot of programming. Thanks for the response.
Title: Re: Set focus to Excel and back
Post by: Lee Mac on December 08, 2015, 12:20:41 PM
I tried
Code - Auto/Visual Lisp: [Select]
  1.       'appactivate "Microsoft Excel - Filename.xlsx")
but it doesn't pause for user input.
Am I using this correctly?

My suggestion didn't include the 'pause', but rather was a suggestion of how to switch focus between applications.