LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

GetOpenFilename doesn't get focus

I'm using the ActveX (Excel) method GetOpenFilename to pop up a dialog box to open an Excel spreadsheet.  This worked properly under Wndows XP and Excel 2003.  With Labview 2010, Excel 2010 and Windows 7, both Excel and the dialog box pop-up behind the running VI.  I plan to hide Excel, but I'd like to know if there is an easy way to give focus to the dalog box when it runs so the user doesn't have to hunt for it.  I suppose I could use the Winapi to give Excel focus after starting, but I was wondering why this functionality changes and if there was anything easier to try. 

 

Note: ActivateMicrosoftApp doesn't work under Excel; there is no Index for it (xlMicrosoftExcel doesn't exist).

 

 

0 Kudos
Message 1 of 6
(4,844 Views)

PointOnePa,

 

Not having access to Office 2010, I was not able to reproduce your issue.  However, it seems like this is probably a change in the functionality of this mehtod you are calling.  I would recommend looking into the Microsoft documentation for the new version of Office, or contacting Microsoft support for further help on this issue.

 

Good Luck!

 

Drew T.

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 2 of 6
(4,833 Views)

Morgan Sweatt, Application Engineer from NI suggested that I could use the approach at the URL below to bring the window into focus.  I tried it using the Handle "Microsoft Excel" and it seems to work.  UpdatedExcel Demo3.VI attached.  This seemed to work okay even if Excel was already open and if I ran two versions of this same program.

 

Programmatically Move Any Window to the Front

http://decibel.ni.com/content/docs/DOC-4745

https://decibel.ni.com/content/servlet/JiveServlet/download/4745-1-6110/SetForegroundWindow_LV86.vi

 

0 Kudos
Message 3 of 6
(4,819 Views)

PointOnePa,

 

I spoke with Morgan and he showed me a similar, yet slightly more efficient and robust, way to do the what you have accomplished in your attachment.  I have created a community example to display this functionality.

 

http://decibel.ni.com/content/docs/DOC-15791

 

In the example, the VI takes the handle from the Excel window that was just created programmatically and sends it to the SetForegroundWindow function.  This makes sure you bring the correct window forward, if there are multiple excel windows.

 

Enjoy!

 

Drew T.

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 4 of 6
(4,812 Views)

Great, that's even better yet.  It also brings the dialog box created by GetOpenFilename to the front with Excel not visible, which is what I originally was trying to do.  Thanks.  (note, while loops without a wait really suck the cpu performance, so I added a "wait until 250ms" in the attached example.

 

 

0 Kudos
Message 5 of 6
(4,800 Views)

Sure, thats a good idea.  It was never intended as a turnkey solution, just a way to pause the program, but your way is better for performance.  Thanks!

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 6 of 6
(4,783 Views)