Hello everyone,
I found the answer to my previous question (open Excel file with iLogic rule) which was very simple:
ThisDoc.Launch("D\...\...xlsx")
Without knowing where to look for a solution, it became a challenge...learning it all by myself.
Now, my assembly file opens, as well as the Excel input data spreadsheet; which is convenient (I had it linked, not embedded, to corresponding parts of the assembly).
I am looking for a code which would force the Excel file to close when the assembly file closes.
Again, it might be very simple but I couldn't find anything working so far...and I would not post a question without exhausting my search efforts first.
I would appreciate your help very much.
Solved! Go to Solution.
Solved by Lancasterm. Go to Solution.
Try this piece of code
ThisDoc.Launch(<excel file to launch>)
ObjXL=GetObject(<excel file that you opened>)
<code to do stuff>
ObjXL.Application.Quit
ThisDoc.Launch("C:\Book1.xls")
ObjXL=GetObject("C:\Book1.xls")
< >
ObjXL.Application.Quit
Also look at this information to customize what gets closed and etc: http://stackoverflow.com/questions/1405742/with-vba-how-do-i-close-an-excel-workbook-without-closing...
Hi sergueiv,
You can find an ilogic example at this link as well:
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
I was able to figure out a work around that works. The difference is that I’m using an embedded excel spreadsheet but it will still work for what you need. I would not suggest doing it this way unless you can’t find any other way that works.
Excel:
You can make a quick macro in side excel that will close excel if you fill in a designated cell (let just say Sheet 2 cell A1) with a “Yes”. You will need to make another macro that will clear the cell when opening the excel document.
Inventor:
Make an iLogic rule with the code below that has an event trigger when inventor is closed.
GoExcel.CellValue("3rd Party:Embedding 5", "Sheet2", "A1") = ”Yes”
I know this is the not the best or the easiest way to get what you want but I know that it works. Just in case you can’t get the other ways to work.
Hope this helps.
Thanks
JD
A macro like this one can be used in excel.
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") = "Yes" Then
Selection.ClearContents
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Sub Macro1()
Thank you very much Lancasterm, Curtis_Waguespack, jddickson!
The best solution was:
ThisDoc.Launch("DATA.xlsx")
'the spreadsheet opens together with the assembly file, triggered by the "After Open Document" event and,
ObjXL=GetObject("D\........\DATA.xlsx")
ObjXLApplication.Quit
'the spreadsheet closes right after the assembly file is closed, triggered by "Close Document" event.
My best regards,
Serguei