powershell에서 통합 문서의 매크로를 시작하고 있습니다 (프로세스 자동화). powershell의 아래는 Excel 통합 문서를 열고 프로세스를 시각화하지 않고 매크로를 실행합니다.
문제는 매크로가 실행되지 않는데도 매크로에서 생성 된 새 Excel 인스턴스가 여전히 열려 있다는 것입니다.
# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'C:\file\Book1.xlsm'
$workbook = $excel.Workbooks.Open($FilePath)
#access the Application object and run a macro
$app = $excel.Application
$app.Run("macro")
#close excel
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Start-Sleep 1
'Excel processes: {0}' -f @(Get-Process excel -ea 0).Count
Remove-Variable $excel
exit $LASTEXITCODE
Excel 파일은 여전히 작업 관리자의 프로세스로 나타나고 메모리 공간을 차지하고 있습니다.
매크로를 통해 열리는 Excel 응용 프로그램의 인스턴스를 Powershell에서 완전히 닫는 방법은 무엇입니까?
어떤 도움이라도 대단히 감사합니다!
COM 개체를 해제하기 전에 다음과 같이 Quit 메서드를 사용해보십시오 .
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Remove-Variable excel
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다