2014-02-26 2 views
1

Access VBA를 통해 통합 문서를 열고 visible = False로 설정 한 다음 무언가를하고 닫습니다. 그러나 그것은 여전히 ​​Taskmanager에서 실행 중입니다.Excel 통합 문서가 여전히 프로세스에서 실행중인 VBA 코드를 통해 닫았습니다.

 Dim ExcelApp As New Excel.Application 
    Dim ExcelBook As New Excel.Workbook 
    Dim rng As Excel.Range 
    Dim rngDefine As Excel.Range 

    Set ExcelBook = ExcelApp.Workbooks.Open("C\temp\find.xlsm") 
    ExcelApp.Visible = False  

    '//Do something 

    ExcelApp.Quit 
    ExcelBook.Close SaveChanges:=False 
    Set ExcelBook = Nothing 
    Set ExcelApp = Nothing   
+3

Excel을 종료하기 전에 통합 문서를 닫습니다. –

+0

@Doug Glancy 감사합니다. – vuyy1182

답변

2

위의 설명자는 맞지만 새 통합 문서는 ExcelApp 인스턴스와 관련이 없습니다. 그래서 결국 새로운 ExcelApp 인스턴스를 닫고 내가 작성한 새 통합 문서를 닫습니다.하지만 새로운 통합 문서가 새로운 Excel 인스턴스에서 열리는 것 같아요. 어쩌면 고아원 Excel 프로세스가 계속 표시 될 것입니다. 작업 관리자. 코드를 다음과 같이 변경하면됩니다.

Dim ExcelApp as Excel.Application 
Dim ExcelBook as Excel.Workbook 
Dim rng As Excel.Range 
Dim rngDefine As Excel.Range 
Set ExcelApp = New Excel.Application 
Set ExcelBook = ExcelApp.Workbooks.Open("C\temp\find.xlsm") 
'ExcelApp.Visible = False You could maybe comment this out unless you use ".Activate" somewhere. It should be the default anyway. 
... 
'At the end: 
ExcelApp.DisplayAlerts = False 
ExcelBook.Close 
ExcelApp.DisplayAlerts = True 
ExcelApp.Quit 
'If right before "End Sub" the next two lines are of arguable necesity, but likely good practice 
Set ExcelBook = Nothing 
Set ExcelApp = Nothing 
+0

아주 최근에이 두통을 겪었으므로 자격이없는 범위 나 워크 시트 또는 통합 문서를 한 번만 사용하면 프로세스를 계속 열어 둘 수 있다고 언급하고 싶습니다. 통합 문서의 모든 단일 명령은 완전히 참조해야합니다. excelapp.excelbook.excelsheet.range ("A1") 내 .Find 함수가 인수에 정규화되지 않은 "Range"를 포함 할 때까지 나는 이것으로 하루를 미쳤습니다. – Acantud

+0

@Acantud I 가끔씩 그렇게하는 것이 지나치게 엄격한 것처럼 느껴지지만, 내가 계속 지켜 보는 기묘한 "OLE 자동화 오류"로 인해 모든 것을 희미 해지고 개체로 설정하기 시작했습니다. 모든 것을 완전히 잠궈 버리면 그것을 피하는 것 같았습니다. – MattB

관련 문제