Tja, da sich noch keiner gemeldet hat, hier der Quellcode:
Private Sub ChangeDefaultFactoryMember(index As Long)
' Get the iPartFactory for the current document.
Dim oFactory As iPartFactory, oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Set oFactory = oDoc.ComponentDefinition.iPartFactory
Dim oApp As Inventor.Application
Set oApp = GetObject(, "Inventor.Application")
ThisApplication.SilentOperation = False
' Get the Excel spreadsheet from the factory. You'll need to
' use the Tools->References command to reference the
' "Microsoft Excel Object Library" to have access to the
' Excel objects.
Dim oSheet As Excel.WorkSheet
Set oSheet = oFactory.ExcelWorkSheet
Dim oCell
oCell = oSheet.Cells(1, 1)
'Split the default cell's string every time to replace the row number
Dim aDefCell()
aDefCell = SplitDefaultString(CStr(oCell))
oCell = aDefCell(0) + CStr(index) + aDefCell(1) ' Aktuelle Zeile setzen!!
oSheet.Cells(1, 1) = oCell ' Zum Updaten!
' Save the changes and quit Excel.
Dim oWorkBook As Excel.Workbook
Set oWorkBook = oSheet.Parent
'At this point, Inventor might be asking about updating the part but
'The point that the dialog pops varies so multiple 'Yes' are passed
'Since Inventor just eats keystrokes, this is safe.
oWorkBook.Save
SendKeys "Y"
DoEvents
oDoc.Update
SendKeys "Y"
DoEvents
oWorkBook.Close
SendKeys "Y"
DoEvents
Set oWorkBook = Nothing
Set oSheet = Nothing
'Leaves one session of Excel Running but if you close excel, it will crash
' both Excel and Inventor so just leave it open. It will close itself later.
Set oDoc = Nothing
Set oFactory = Nothing
Set oApp = Nothing
End Sub
Private Function SplitDefaultString(sDefStr As String) As Variant
Dim aDefString(), pos1 As Integer, pos2 As Integer
ReDim aDefString(1)
pos1 = InStr(1, sDefStr, "<defaultRow>", vbBinaryCompare)
pos2 = InStr(pos1 + 9, sDefStr, "</defaultRow>", vbBinaryCompare)
aDefString(0) = Left(sDefStr, pos1 + 11)
aDefString(1) = Right(sDefStr, Len(sDefStr) - pos2 + 1)
SplitDefaultString = aDefString
End Function
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP