LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Check if excel workbook open ActiveX and obtain workbook reference

Solved!
Go to solution

Hi,

 

I want to read data from the first worksheet of an excel workbook regardless of it's state:

1) Opened

2) Closed

...without any prompts.

 

Closed is the easy part because the workbook is not open.

 

If the work workbook is open, and you attempt to open it to obtain a reference it says something like "Workbook is already open. Opening it again will discard changes."

 

The question of the day: How to obtain a reference for an already opened workbook without Excel prompting? Assuming I JUST referenced the specific Excel application.

 

Thanks,

Aric

 

 

0 Kudos
Message 1 of 14
(6,432 Views)

Setting DisplayAlerts to F might help - http://msdn.microsoft.com/en-us/library/office/ff839782.aspx

 

If it doesn't, I would suggest a Google search. What applies to other languages should also apply here. I haven't tried, but I would expect that if you call the Count property on the app's Workbooks property, you will get 0 if none exist.


___________________
Try to take over the world!
Message 2 of 14
(6,404 Views)

I don't post unless I've googled! Thanks for the reply.

 

The DisplayAlerts will automatically select "reopen without keeping changes" but I want the "save then reopen" functionality. Or an alternative method of obtaining the workbook reference, if opened already.

0 Kudos
Message 3 of 14
(6,379 Views)
Solution
Accepted by topic author abeaver

Yes, the count method works. I just didn't know about the _Application.ActiveWorkbook functionality. Here is a working block diagram.

 

excel workbook already open activex.JPG

excel workbook already open activex2.JPG

excel workbook already open activex3.JPG

 

 

0 Kudos
Message 4 of 14
(6,373 Views)

Here is another option for checking if open/getting an open workbook reference that I have used in the past. I think this is a working version of it anyways. Admittedly, I didn't double check.

 

Message 5 of 14
(6,360 Views)

I'm trying to do something similar, write to an existing and open Excel file.  Other excel files will be open so I need to make sure that the correct one is selected an active.  Can you explain what is in your "refnum cluster in"?  is it the excel reference and filename path? thanks

0 Kudos
Message 6 of 14
(6,098 Views)

@JessicaM wrote:

I'm trying to do something similar, write to an existing and open Excel file.  Other excel files will be open so I need to make sure that the correct one is selected an active.  Can you explain what is in your "refnum cluster in"?  is it the excel reference and filename path? thanks


abeaver's Refnum Cluster has the refnums for the Excel Application and the Excel Workbook. Nothing special.

0 Kudos
Message 7 of 14
(6,090 Views)

Thanks.  I was able to get abeaver's program to work, but I'm still missing the ability to be able to select and make a specific workbook the active one if other workbooks are also open.  For instance, I want my program to open and write to a file called Text.xls.  I can get the program to do this.  However, if i have another workbook open, say Data.xls, I can't seem to get the program to recognize the difference between the two files.  When it checks to see if the workbook is open, it's checking to see if any workbook is open, not Test.xls specifically.  So, when it writes data, it writes it to whichever Excel workbook is currently active.  Is there a way to get the program to check for and make a specific workbook if other workbooks are also open? thanks

0 Kudos
Message 8 of 14
(6,049 Views)

@JessicaM wrote:

Thanks.  I was able to get abeaver's program to work, but I'm still missing the ability to be able to select and make a specific workbook the active one if other workbooks are also open.  For instance, I want my program to open and write to a file called Text.xls.  I can get the program to do this.  However, if i have another workbook open, say Data.xls, I can't seem to get the program to recognize the difference between the two files.  When it checks to see if the workbook is open, it's checking to see if any workbook is open, not Test.xls specifically.  So, when it writes data, it writes it to whichever Excel workbook is currently active.  Is there a way to get the program to check for and make a specific workbook if other workbooks are also open? thanks


http://msdn.microsoft.com/en-us/library/office/ff835568%28v=office.14%29.aspx

convert to LabVIEW

0 Kudos
Message 9 of 14
(6,030 Views)

@nyc_(is_out_of_here) wrote:

http://msdn.microsoft.com/en-us/library/office/ff835568%28v=office.14%29.aspx

convert to LabVIEW


 

I admit that I am not good with ActiveX, and am having some trouble figuring out how to convert to LV.  Do you have any suggestions or examples?  I have searched through most of the forums and the Excel toolkit but am coming up empty on how to select a specific workbook if a bunch of workbooks are open...

0 Kudos
Message 10 of 14
(6,015 Views)