It sounds like we need to know more details, before we can help you further.
When you post what the error message says, capture the text or screen captured image from both tabs of the error message. Often the second tab contains much more information, and may give us a clue as to where in the code it is having a problem.
Also, there are many different ways to "debug" (find and/or weed out potential errors) in code, and we may have to include one of these techniques here, to give us a better understanding of where,when, and why it is either throwing errors, or not working as expected. If you have Inventor 2019.1 (I believe) or later then you should have the iLogicLog tab available (or can be turned on), and the ability to write things to the iLogic log as your code starts, progresses, and ends (depending on how you set it up and what level of the Log you are using). Or as a "fast & loose" option, you could put something like MsgBox(1), or MsgBox(2)...etc after each line within your code, then when you run it, pay attention to the last number it shows before it throws an error, and that will tell you that the next line after that numbered MsgBox() is where it is having trouble.
Then there are ways to attempt to avoid expected errors. The current standard for this within iLogic (vb.net) is the Try...Catch...End Try block. Within the Try portion, you try to do what you want, then in the Catch portion you put what do do if the Try portion fails. This can be very useful to prevent your code from abruptly stopping because of an error, and if you property utilize the Catch portion, it can potentially give you very meaningful feedback as to what went wrong.
Here is an updated version of my earlier code that includes another "check" and a couple of Try...Catch...End Try blocks in there, that I'm hoping will offer some meaningful feedback. Let me know how this works out for you, and any messages you're seeing if things don't fully work.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
Return
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet
Dim oView As DrawingView
Dim oViewDoc As Document
For Each oSheet In oDDoc.Sheets
If oSheet.DrawingViews.Count > 0 Then
For Each oView In oSheet.DrawingViews
Try
oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Catch
MsgBox("A Model document couldn't be retrieved from the following View:" & vbCrLf & _
"Sheet: [" & oSheet.Name & "] View: [" & oView.Name, vbOKOnly + vbInformation, " ")
Continue For
End Try
Try
oViewDoc.Save()
Catch
MsgBox("We've found the Model document in the following View:" & vbCrLf & _
"Sheet: [" & oSheet.Name & "] View: [" & oView.Name & vbCrLf & _
"But the attempt to simply Save (not SaveAs) failed.", vbOKOnly + vbCritical, " ")
End Try
Next
End If
Next
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
Wesley Crihfield

(Not an Autodesk Employee)