Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with closing Excel file

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
AERE
1308 Views, 5 Replies

Help with closing Excel file

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.

Tags (1)
5 REPLIES 5
Message 2 of 6
Lancasterm
in reply to: AERE

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...

 

 

Message 3 of 6
Curtis_Waguespack
in reply to: AERE

Hi sergueiv,

 

You can find an ilogic example at this link as well:

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/How-to-create-a-excel-file-using-ilogi...

 

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

Message 4 of 6
jddickson
in reply to: AERE

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

Message 5 of 6
jddickson
in reply to: AERE

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()

Message 6 of 6
AERE
in reply to: Lancasterm

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report