Message 1 of 3

Not applicable
05-30-2017
01:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
See code - I am missing something that can get the "part" which is a member of the "parts" range sent to the private sub with the false modifier.
I get an error that says, "object required."
It's some kind of basic syntax thing, provided everything else is working.
I've attached the spreadsheet I'm using - it's had some editing, as I get better I want to use these as they come from our client.
Sub HideParts() Dim oApp As Application Set oApp = ThisApplication Dim oDoc As Document Set oDoc = oApp.ActiveDocument ' Check if user is in part or assembly If oDoc Is Nothing Or TypeOf oDoc Is DrawingDocument Then Exit Sub End If Dim oCompDef As ComponentDefinition ' Get component definition Set oCompDef = oDoc.ComponentDefinition 'Dim oParams As Parameters 'Dim oParam As Parameter ' Get parameters object (JG: don't need this?) 'Set oParams = oCompDef.Parameters ' define wsheet variable, etc Dim exapp As Excel.Application Dim wsheet As Excel.WorkSheet Dim part As Excel.Range Dim parts As Excel.Range 'What does this do? 'It sucks in air 'It's definitely sucking... Dim pt(2) As Double Set exapp = CreateObject("Excel.Application") 'this actually works to set the path: Dim sFilePath sFilePath = exapp.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", Title:="Select Work Order") 'pop open excel visibly so I know I have the right file and workbook open (for now...) exapp.Visible = True exapp.Workbooks.Open sFilePath Set wsheet = exapp.ActiveSheet 'Seems reasonable Set parts = wsheet.Range("I2:I87") parts.Select pt(0) = 0: pt(1) = 0: pt(2) = 0 For Each part In parts Call SetVisibility(oAsmDoc.ComponentDefinition.Occurrences, part.Text, False) pt(0) = pt(0) + 1 pt(1) = pt(1) + 1 Next part End Sub Private Sub SetVisibility(Occurrences As ComponentOccurrences, SearchName As String, VisibilityOn As Boolean) ' Iterate through each of the occurrences in the collection provided. Dim oOccurrence As ComponentOccurrence For Each oOccurrence In Occurrences ' Check to see if the occurrence name matches the search name. ' The strings are converted to upper case to remove context sensitivity. If UCase(oOccurrence.Name) Like UCase(SearchName) Then ' Check to see if the visibility is different than the specified visiblity. If oOccurrence.Visible <> VisibilityOn Then ' Set the visibility of the occurrence. oOccurrence.Visible = VisibilityOn End If End If ' If this occurrence is a subassembly, recursively call this ' function to traverse through the subassembly. If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then Call SetVisibility(oOccurrence.SubOccurrences, SearchName, VisibilityOn) End If Next End Sub
Thanks in advance if anyone can help me out!
James
Solved! Go to Solution.