0

この VBA の問題は Microsoft Office にも当てはまる可能性がありますが、私は objectで経験していますInventor.Sheet。VBA+Office経験のある方もお気軽にご回答ください。

InitializedInventor.Sheetは次のように使用できます。

Debug.Print oSheet.TitleBlock.Name ' prints "Title Block 1"

また、

Debug.Print oSheet ' prints 11234869 long integer, value of default member

この二元的な動作は、オブジェクトのデフォルト プロパティによって引き起こされます。

問題は、私が使用するたびに

Dim TitleBlocksLargestSheet As Scripting.Dictionary
TitleBlocksLargestSheet.Add oTitleBlock, oSheet

次に、辞書に追加すると、へのオブジェクト参照の代わりに長整数値が挿入されoSheetます。

どのようにオブジェクト参照を辞書に挿入できますか?

両方が可能な場合、辞書法は操作の前に操作Addを好むのではないかと思います。=Set

したがって、次の例では、常にオブジェクトではなく辞書項目の整数になります。

'*** get a dictionary of used title blocks (corner stamps) with largest sheet size for each
For Each oSheet In oDrawingDocument.Sheets

    '** get title block of active sheet
    Dim oTitleBlock As Inventor.TitleBlock
    Set oTitleBlock = oSheet.TitleBlock

    If Not oTitleBlock Is Nothing Then
        '** add or update title block usage
        If Not TitleBlocksLargestSheet.Exists(oTitleBlock) Then
            TitleBlocksLargestSheet.Add oTitleBlock, cobj(oSheet)
        Else
            Dim oLargestSheetSeen As Inventor.Sheet
            Set oLargestSheetSeen = TitleBlocksLargestSheet(oTitleBlock)
            If oSheet.Width * oSheet.Height > oLargestSheetSeen.Width * oLargestSheetSeen.Height Then
                TitleBlocksLargestSheet.Item(oTitleBlock) = oSheet
            End If
        End If
    End If
Next oSheet

-- *** usage - retrieval from the dictionary
For Each oSheet In TitleBlocksLargestSheet.Items 'ERROR 424: Object required.
    Set oTitleBlock = oSheet.TitleBlock
    '...some other code
Next oSheet

アップデート:

Debug.Print TypeName(TitleBlocksLargestSheet.Item(oTitleBlock))
IRxSheet ' perhaps there's no problem with storage but with retrieval?
Debug.Print VarType(TitleBlocksLargestSheet.Item(oTitleBlock))
3  ' (Long Integer)
4

1 に答える 1