Hi @JoãoASilva. Do you mean that the document's tab is staying open after the 'Close' line of code? Or do you just mean that the total number of open documents shown in the lower right corner of the screen does not go down after closing them? If the document tab is not going away after the Close line, then something odd is definitely going on. However, the total number of open documents will not go down, because of what I mentioned earlier. Since that document is being referenced by the assembly, it it most likely already at least initiated, if not already open, and your code for opening it visibly, then closing it, will not change that status. It will still be open by the assembly after it has been visibly closed, because it is still being referenced by the assembly. If you opened that referenced document, then closed the assembly that was referencing it, then closed that document, then the number/count representing that document should go away.
As an example, I just typed up this example rule. It lets me 'Pick' an assembly component, then gets its FullDocumentName, then visibly opens it, then shows me its FullDocumentName in a MsgBox, then closes the document again. During that process, the number of open documents never changes, because that part was already open in the background (no document tab) by the assembly, and remains open in the background by the assembly after it has been visibly closed (document tab from opening it visibly goes away). This example also shows using a variable to capture the Document that the 'Open' method returns. In your case, since you already had the 'oDocFile' variable that had already been defined as a Document, that variable could be used again to capture the value returned by that line of code. This is because traditionally, you would not use that line of code to open a document that you already have a Document type reference for, but one that you only have a FullFileName or FullDocumentName (String) for. If all you had was a String, then that line of code is the only way to obtain a reference to the Document object, instead of just the String.
Dim oPickedOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
If oPickedOcc Is Nothing Then Return
Dim sFDN As String = oPickedOcc.ReferencedDocumentDescriptor.FullDocumentName
Dim oPickedOccDoc As Inventor.Document = ThisApplication.Documents.Open(sFDN, True)
MsgBox(sFDN, vbInformation, "iLogic")
oPickedOccDoc.Close
When I have an assembly visibly open and one of the components in it has multiple ModelStates, and that component is not currently visibly open, I can 'Pick' that component using this rule, visibly open it (document tab showing and that part showing on screen), then close it, which closes that document tab, and leaves me viewing the assembly again. The total open documents number does not change.
Wesley Crihfield

(Not an Autodesk Employee)