Excel 파일을 열고 매크로를 실행하고 닫는 VBScript 코드가 있습니다. 벌금.Excel 파일을 열어 두는 VBScript 코드
지금 변경하고 싶은 것은 파일을 열어 두는 것입니다.
xlApp.activewindow.close 및 xlApp.Quit 코드 2 줄을 제거하면 통합 문서와 응용 프로그램이 닫히지 만 백그라운드에서 열린 상태로 유지됩니다 (Excel 프로세스가 여전히 작업 관리자에서 활성화되어 있음). 따라서 스크립트를 다시 호출하여 동일한 파일에서 나중에 매크로를 다시 실행할 수 없습니다 (정확하게 수행하고 싶은 작업 임).
왜? 여기
코드입니다 :Option Explicit
On Error Resume Next
MyTest
Sub MyTest()
Dim xlApp
Dim xlBook
Dim fpath
Dim fname
' Excel application running? if not, open Excel
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If xlApp <> "Microsoft Excel" Then
Set xlApp = CreateObject("Excel.Application")
End If
Err.Clear
' correct Excel file open? if not, open it
fpath = "D:\Desktop\"
fname = "MyTest.xls"
xlApp.Workbooks(fname).Activate
If Err = 0 Then
' no error, so it has been possible to activate the workbook
Set xlBook = xlApp.Workbooks(fname)
Else
' unable to activate, so workbook was not open -> open it now
Set xlBook = xlApp.Workbooks.Open(fpath & fname, 0, True)
End If
Err.Clear
' now run the desired macro in the excel file
xlApp.Run "HelloWorld"
' WANT TO CHANGE THIS
xlBook.saved = True
xlApp.activewindow.close
' AND THIS
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
"작동하지 않는 것"이 무엇입니까 ?? –
내가 불분명하면 죄송합니다. 작동하지 않는 것은 파일을 열어 두는 것입니다. 'xlApp.activewindow.close'와'xlApp.Quit' 코드의 두 줄을 제거하면 통합 문서와 응용 프로그램이 닫히지 만 백그라운드에서 열리게됩니다 (Excel 프로세스는 여전히 작업 관리자에서 활성화되어 있습니다). 따라서 스크립트를 다시 호출하여 동일한 파일에서 나중에 매크로를 다시 실행할 수 없습니다 (정확하게 수행하고 싶은 작업 임). – user986990
여전히이 두 줄을 스크립트에 남겨 두시겠습니까? : xlBook = Nothing 설정 xlApp = Nothing –