iPart Excel

iPart Excel

Anonymous
Not applicable
383 Views
3 Replies
Message 1 of 4

iPart Excel

Anonymous
Not applicable
Dear members,

Can we automate using VBA the process of copying from a Excel file which contains the rows and columns of standard part catalogue to the iPart Author Excel which is embedded inside iPart without a file name (can't find the location of the Excel file)?

If it is possible, can you please kindly show me some sample codes?

Thank you.

Dong
0 Likes
384 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
I've attached a macro below that should do what you want. Make sure you add
a reference to the Excel type library and change the path of the source
excel file in the macro.

Sanjay-

Public Sub CopyExcelSheet()

Dim oFactoryDoc As PartDocument
Set oFactoryDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
Set oDef = oFactoryDoc.ComponentDefinition

Dim oWorkSheet As WorkSheet
Set oWorkSheet = oDef.iPartFactory.ExcelWorkSheet

Dim oWorkBook As Workbook
Set oWorkBook = oWorkSheet.Parent

Dim oExcelApp As Excel.Application
Set oExcelApp = oWorkBook.Application

' Delete the existing worksheet
oWorkSheet.Delete

Dim oSourceWorkBook As Workbook
Set oSourceWorkBook = oExcelApp.Workbooks.Open("C:\temp\Source.xls")

oExcelApp.Windows(oWorkBook.Name).Visible = True

' Copy the worksheet from the source workbook
oSourceWorkBook.Sheets("Sheet1").Copy Before:=oWorkBook.Sheets(1)

oSourceWorkBook.Close
oWorkBook.Save
oWorkBook.Close

oExcelApp.Quit

End Sub

wrote in message news:5733450@discussion.autodesk.com...
Dear members,

Can we automate using VBA the process of copying from a Excel file which
contains the rows and columns of standard part catalogue to the iPart Author
Excel which is embedded inside iPart without a file name (can't find the
location of the Excel file)?

If it is possible, can you please kindly show me some sample codes?

Thank you.

Dong
0 Likes
Message 3 of 4

Anonymous
Not applicable
Dear Sanjay,

Thank you very much for the macro. It's great and work out fine.

But there is a pop up message box which states

"Data may exist in the sheet(s) selected for deletion. To permanently delete the data, press Delete."

Can we automate the process of pressing "Delete" button?
Is it possible we simulate the pressing of "Delete" button in VBA?

Thank you.

Dong
0 Likes
Message 4 of 4

Anonymous
Not applicable
It seems like you have the Excel application open when running this macro. I
was assuming that Excel would not be running and you don't have any excel
sheet open. There will be no prompts in this situation.

If you do need to have Excel running, you can disable the prompts using this
line:

oExcelApp.DisplayAlerts = False

Make sure to set the flag to True after deleting the sheet.

Also note that if Excel is already running the macro will shut it down (in
the line oExcelApp.Quit). You may want to account for that.

Sanjay-


wrote in message news:5740453@discussion.autodesk.com...
Dear Sanjay,

Thank you very much for the macro. It's great and work out fine.

But there is a pop up message box which states

"Data may exist in the sheet(s) selected for deletion. To permanently delete
the data, press Delete."

Can we automate the process of pressing "Delete" button?
Is it possible we simulate the pressing of "Delete" button in VBA?

Thank you.

Dong
0 Likes