Form executing a rule in Excel: Annoying message appears about reopening file

Form executing a rule in Excel: Annoying message appears about reopening file

Anonymous
Not applicable
407 Views
5 Replies
Message 1 of 6

Form executing a rule in Excel: Annoying message appears about reopening file

Anonymous
Not applicable

Hello,

I have a Form where you write the part number and give the status of the part. Than you run the rule that I wrote and the given data is tranfered to the excel sheet. It all works well but as soon as I change something in my form,  I get this annoying messege (in German). It say something like this: 

"the excel file is already open,. if I reopen it  I will loose my changes that I gave in. Should the file be reopened?"

This messege appears even if I close the excel file. The messege and my code are in pictures. Is there a way to avoid this messege? It all works fine after all (I think) .

Best, Lukas11.PNG22.PNG

0 Likes
408 Views
5 Replies
Replies (5)
Message 2 of 6

JamieVJohnson2
Collaborator
Collaborator

The excel file may be 'closed' but as long as some thread (excel or inventor) is still using it, it will stay open in memory.

 

Why not check to see if the workbook is already open, then access it from the workbooks collection of the excel application if it is, and open it if it is not?

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for the answer,

would you please be more specific how to do that?

0 Likes
Message 4 of 6

JamieVJohnson2
Collaborator
Collaborator

Start with getting an instance of the Excel.Application object and store it in a variable.

then use that instance variable to query the sub object Excel.Application.Workbooks

Next iterate through the workbook objects found in the workbooks collection, and verify the name or filename against the workbook you are attempting to use.

When you find the workbook you are attemting to use, save to your workbook instance variable, and use it.

Here you can either close the workbook, or just start using it as is.

If you complete the enumeration and don't find your workbook, then attempt to create a new one using workbooks.open or workbooks.new.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 5 of 6

Anonymous
Not applicable

hm I stil believe, that there should be a simplier solution. Obviously im doing something wrong, maybe it has something to do with my code? I use "GoExcel.CellValue (file name, sheet name, Cell)= somehting" for every single value that I put in. I end my code with GoExcel.Save and GoExcel.Close

That message appears as soon as i change any of the values in the form.

First I get the message i explained above. When I choose, yes, I get anotherone (see the attached picture). It says: a file with the name (name of the file) is already existing in this saving destinationn. Should it be replaced?

Thanks again,2.PNG

 

0 Likes
Message 6 of 6

JamieVJohnson2
Collaborator
Collaborator

That note should only be displayed if Excel is running a 'SaveAs' command.  Excel will only turn a 'Save' command into a 'SaveAs' command automatically if the file on the drive is marked 'read only' or opened as 'read only'.  Perhaps # of threads is getting involved.  Example, Excel 1 has file open, a second Excel 2 thread is created (hidden or not) to process on the same file, but Excel 1 will not release control of the file, even after it is closed.  This behavior I've seen when trying to delete a file from the drive.  To eliminate this issue, make sure you open excel only once per session, and keep a reference to that excel.  I don't know the exact code behind GoExcel, but it does return the Excel.Application, so it has to use martial commands written in my get excel code.  Problem with iLogic, is scope.  When your project scope is within a single file, you are opening and closing Excel over and over, instead of reusing it for a single work session for multiple files.  If you code was in VBA (or .Net) it could persist an instance value of Excel.application, even if you close all your documents.  Anybody listening, can variable persistence be done in iLogic, if you close all documents?

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes