Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Excel remains open

tecnico
Contributor

Excel remains open

tecnico
Contributor
Contributor

I have this ilogic rule:

It works perfectly, the only issue I have is that the ARTICOLI.xlsm Excel file from which the macro starts remains open in the background.

How can I make sure it closes?

Thank you"

' IMPORTA IL LAYOUT DI DISTINTA
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oBom As BOM = doc.ComponentDefinition.BOM
oBom.ImportBOMCustomization("K:\18_UFFICIOTECNICO\CON_INV\Templates\struttura distinta_SONAR_ARTICOLI.xml") ' Percorso del layout della distinta da attivare per SONAR ARTICOLI

' VERIFICA IL NOME DEL COMPONENTE PRINCIPALE
Dim nameVRpart As String = iProperties.Value("Project", "Part Number")
If nameVRpart.Contains(" ") Then
    Dim modnomeprt As DialogResult = MessageBox.Show("Il nome della parte di assieme contiene spazi, aggiornare il numero parte? Attenzione, l'assieme deve essere estratto!!!!!", "Attenzione", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
    If modnomeprt = DialogResult.Yes Then
        Dim myparam As String = InputBox("Inserire il numero parte", "Numero parte", "Inserisci il nome della parte")
        iProperties.Value("Project", "Part Number") = myparam
    End If
End If

' CREA PARTE VIRTUALE
iLogicVb.RunExternalRule("K:\18_UFFICIOTECNICO\CON_INV\Templates\Regole utili Lampocar\crea parte vituale.txt")
'iLogicVb.RunExternalRule("K:\18_UFFICIOTECNICO\CON_INV\Templates\Regole utili Lampocar\assegna item 0 e posiziona in testa.txt")
iLogicVb.RunExternalRule("K:\18_UFFICIOTECNICO\CON_INV\Templates\Regole utili Lampocar\sincronizza ipropreties parte virtuale.txt")

Dim DOVE As String = "K:\18_UFFICIOTECNICO\CON_INV\ESPORTAZIONE\"
Dim NOME As String = ThisDoc.FileName(False) ' Senza estensione
Dim DATA As String = DateString
Dim fileName2 As String = DOVE & NOME & "_ARTICOLI_" & DATA & ".xlsx"
ThisBOM.Export("Strutturata", fileName2, kMicrosoftExcelFormat)

GoExcel.Open(fileName2, "Sheet1")
i = GoExcel.FindRow(fileName2, "Sheet1", "Numero parte", "=", iProperties.Value("Project", "Part Number"))
cellmass = "G" & i
mass = Round(iProperties.Mass, 3)
GoExcel.CellValue(cellmass) = mass
GoExcel.CellValue("D" & i) = Parameter("GRUPPO")
GoExcel.CellValue("E" & i) = Parameter("TIPO")
GoExcel.CellValue("F" & i) = Parameter("CATEGORIA")
GoExcel.CellValue("C" & i) = "PZ"

'iProperties.Mass = GoExcel.CellValue(cellmass)


excelApp = GoExcel.Application
excelApp.Run("'" & "K:\18_UFFICIOTECNICO\CON_INV\Regole esterne per anagrafica\MACRO ESPORTAZIONE\ARTICOLI.xlsm" & "'!SetArt")
excelApp = Nothing
GoExcel.Save
GoExcel.Close

' Elimina parte virtuale
iLogicVb.RunExternalRule("K:\18_UFFICIOTECNICO\CON_INV\Templates\Regole utili Lampocar\eliminazione parte virtuale.txt")

'RIPRISTINA VISTA PRINCIPALE
oBom.ImportBOMCustomization("K:\18_UFFICIOTECNICO\CON_INV\Templates\STRUTTRA_COMPILAZIONE_LAMPOCAR.xml") ' Percorso del layout della distinta da attivare di default

	'PERCORSO DA APRIRE
	oPath = DOVE
	Dim Proc As String = "Explorer.exe"
	Dim Args As String = ControlChars.Quote & oPath & ControlChars.Quote
	Process.Start(Proc, Args)
0 Likes
Reply
Accepted solutions (1)
243 Views
2 Replies
Replies (2)

WCrihfield
Mentor
Mentor
Accepted solution

Hi @tecnico.  I see that your code includes lines of code to save and close the Workbook, but I don't see a line of code to quit the Excel application afterwards.  There might just be some reference to it held in Excel's session memory or something like that.  Try adding the GoExcel.QuitApplication line at the end.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

tecnico
Contributor
Contributor

thank you very much!

0 Likes