Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Where the excel in ipt is saved

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
613 Views, 14 Replies

Where the excel in ipt is saved

I want to access excel.
How can I access it.
I mean I am trying to access embeded excel sheet in ipt.how do I open the excel programtically?
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: Anonymous

I dont think its posible to do this with embeded spreadsheets, as I have tried this in the past. Although you can use linked excel sheets. Attached is my code:

Sub LinkedXlFile()

On Error GoTo ErrHandler
Dim xlApp As Excel.Application, sFile As String
Dim oDoc As Document, oParameters As Parameters, oTable As ParameterTable

Set oDoc = ThisApplication.ActiveDocument
Set oParameters = oDoc.ComponentDefinition.Parameters
Set oTable = oParameters.ParameterTables.Item(1)

sFile = oTable.FileName

Set oDoc = Nothing: Set oParameters = Nothing: Set oTable = Nothing

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True: xlApp.Workbooks.Open (sFile)

Exit Sub

ErrHandler: MsgBox (Err.Description & " in Sub LinkedXlFile"): Err.Clear

End Sub
Message 3 of 15
Anonymous
in reply to: Anonymous

I think linked excel anyway you can open from outside
But i have embeded spreadsheet.

I have idw open as active document I can access parent ipt.
Is it not possible to access the excel which is sitting there in the ipt.i think there has to be same way to access it has anyone experienced this before
Message 4 of 15
Anonymous
in reply to: Anonymous

If you open the embedded spreadsheet from inside inventor, then when in excel go to the file>properties. You will see that the embedded file has no path. I had this problem in 2008, I don't know if 2009 has solved this yet?
Message 5 of 15
Anonymous
in reply to: Anonymous

AFAIK, there is no API access to embedded spreadsheets
Message 6 of 15
Anonymous
in reply to: Anonymous

Belu,

I use this code (modified slightly) to access data in the current iPart. I use standard Excel(2003) VBA to copy data from a true excel file to the iPart file (Product codes/Part Numbers etc), although I can see no reason to not be able to more than just copying and pasting from one sheet to another.

Dim odoc As PartDocument
Set odoc = ThisApplication.ActiveDocument
If odoc.ComponentDefinition.IsiPartFactory Then
Set oiPartFactory = odoc.ComponentDefinition.iPartFactory
End If
Set xlWS = odoc.ComponentDefinition.iPartFactory.ExcelWorkSheet

Hope this helps.

Jon
Message 7 of 15
Anonymous
in reply to: Anonymous

Sorry just realised my mistake!

Will update shortly

Jon
Message 8 of 15
Anonymous
in reply to: Anonymous

Sorry about the false start, I've now had a play about, and got a working sample!

Sub iPartAccess()
On Error Resume Next
Dim xlDocName As Excel.Workbook
Dim oiPartFactory As iPartFactory
Dim xlWS As Excel.WorkSheet
Dim xlApp As Excel.Application
Dim odoc As PartDocument 'Dim odoc As AssemblyDocument (for iAssemblies)
Dim xlName As String

Set odoc = ThisApplication.ActiveDocument
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

If odoc.ComponentDefinition.IsiPartFactory Then
Set oiPartFactory = odoc.ComponentDefinition.iPartFactory
xlName = oiPartFactory.ExcelWorkSheet.FullName
End If
Workbooks.Application.Visible = True

End Sub

This will open the embedded xl sheet outside inventor (but the iPart must be open). There is probably a way to open the xl sheet using Apprentice, but i'm not sure so don't quote me on this.

Anyway, you can make any changes you need in the sheet, and c&p values to other workbooks as required, but remember to change any changes when you close it.

I'm not sure why, but if you delete the xlName line, or the "Workbooks.Application.Visible = True" line, the code doesn't work. Also if you run the code twice you will notice that the file name is different (it opens as a temp file, and as such is assigned a new code each time (I think)).

If you need any more help, I will do my best to help you.

Cheers

Jon
Message 9 of 15
Anonymous
in reply to: Anonymous

jonbrabbs

Thanks for your response,
I am using a part document not ipart factory.
What I am doing is I have some information in embeded excel file.
I want to pass on that information from embeded excel to drawing document.
And I have to run the program from drawing document.

Workaround is
Currently I am saving a copy of embeded excel file in C:\temp folder and then I can access it from VBA.

If you have better idea of workaround then please suggest.
Message 10 of 15
Anonymous
in reply to: Anonymous

If you are referring to an embedded excel sheet created as a result of
referencing an excel sheet from the Parameters dialog, you can access that
worksheet using ParameterTable.WorkSheet property. This property returns an
Excel WorkSheet object which you can query using Excel APIs. Make sure to
add a reference to the Excel type library in Inventor's VBA (go to
Tools->References).

Sanjay-
Message 11 of 15
Anonymous
in reply to: Anonymous

Is this new to '09?

http://discussion.autodesk.com/thread.jspa?messageID=5934218
Message 12 of 15
Anonymous
in reply to: Anonymous

This is not new to Inventor 2009. The API has always provided access to the
embedded spreadsheets IF created using the parameters dialog. What I should
have said in the response to the other thread is that not all embeddings are
exposed via the API. For instance, you can create an embedded excel
spreadsheet using the "Insert->Object..." command. Such embeddings are not
accessible via the API.

Thanks for catching that, Josh.

Sanjay-
Message 13 of 15
Anonymous
in reply to: Anonymous

That's Great.Thanks for your valuable help sanjay.
This opens whole new world of excel through inventor.

Meanwhile I could not find Excel type library inventor VBA
Can you give me the full name of that library please.
Message 14 of 15
Anonymous
in reply to: Anonymous

In VBA, go to Tools -> References and select "Microsoft Excel 12.0 Object
Library" (or the version on your computer).

Sanjay-
Message 15 of 15
Anonymous
in reply to: Anonymous

Thanks Sanjay,I already have this library.

I think there was confusion in earlier threads of definition of embeded sheets ,It is clear now.

API has access to embeded or linked excel sheet which we link or embed in parameter dialogue.But API has no access to excel sheet which embeded by inset-object method.

Thanks

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

Post to forums  

Autodesk Design & Make Report