2017-12-20 13 views
2

excel이 편집 모드인지 확인하려면이 thread을보고 수정하려고 시도했지만 Excel이 있으면 작동하지 않습니다excel이 word-vba의 편집 모드에 있는지 알아보십시오

enter image description here

'********************************************************* 
'********* define if we need to close excel after sub is done 
'*********************************************************** 
Public Function setExcelObject(ByRef oXLApp As Object) As Boolean 
    On Error Resume Next 

    Set oXLApp = GetObject(, "Excel.Application") 
    If oXLApp Is Nothing Then 
     Set oXLApp = CreateObject("Excel.Application") 
    End If 

    setExcelObject = IsInEditMode(oXLApp) 

End Function 


Public Function IsInEditMode(ByRef exapp As Object) As Boolean 
     If exapp.Interactive = False Then 
      IsInEditMode = False 
     Else 
      On Error GoTo terminate 
       exapp.Interactive = False 
       exapp.Interactive = True 

       IsInEditMode = False 

     End If 
     Exit Function 

terminate: 
     IsInEditMode = True 
     Exit Function 

    End Function 

참고 : 그것은 또한에 있음을 알아 내기 위해 끔찍한 긴 (15 초)을 소요 편집 모드에서 다음을 실행 한 후 종료 편집 모드는 여전히 편집 모드 말한다 다시 실행 편집 모드 ...

+0

내가 대화 property' 여기에 사용하는 하나'생각하지 않습니다. [Application.Interactive Property from MSDN] (https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/application-interactive-property-excel)을 확인하십시오. –

+0

'exapp.Interactive = False'를 제거하고 다시 시도 할 수 있습니까? 'On Error GoTo '가 종료 된 후? – Vityata

+0

음, 모르겠다 - 메시지를 생성하는 코드 (Word에서)가 어디에 있는가? "Excel에서 셀을 편집하고 있습니다!"***? 그건 분명히 Office에 내장 된 메시지가 아니므로, 당신이 추가 한 것에서 오는 것입니다. 그것을 찾아, 그러면 당신은 찾을 수 있습니다 ** ** 얼마나 ** 세포가 편집되고 감지하고 있습니다. 모듈 및 CTRL + F로 이동하는 것만 큼 쉽지만 ** 전체 프로젝트 **에서 검색하고 해당 구문의 일부를 검색하도록 선택할 수 있습니다. – ashleedawg

답변

1

다음은 작동 코드입니다.

나는 다음과 같은 몇 가지 절차에서 호출 16,
'********************************************************************** 
'********* See if we can open excel, true is Yes we can work with excel 
'********************************************************************** 
Public Function setExcelObject(ByRef oXLApp As Object) As Boolean 
    On Error Resume Next 

    Set oXLApp = GetObject(, "Excel.Application") 
    If oXLApp Is Nothing Then 
     Set oXLApp = CreateObject("Excel.Application") 
    End If 

    setExcelObject = Not IsInEditMode(oXLApp) 

    If setExcelObject = False Then Set oXLApp = Nothing 

End Function 

' ***************************************************************** 
' **************** Check if excel is in edit mode **************** 
'***************************************************************** 
Public Function IsInEditMode(ByRef exapp As Object) As Boolean 
      On Error GoTo terminate 
       exapp.Interactive = False 
       exapp.Interactive = True 

       IsInEditMode = False 

     Exit Function 
terminate: 
     IsInEditMode = True 
     Exit Function 

    End Function 

' ************************************************************* 
' *************** Check if excel is open, true, means we should not close excel after we are done..... 
'***************************************************************** 
Function ExcelOpen() As Boolean 
    ExcelOpen = FindWindow("XLMAIN", vbNullString) 
End Function 

위의 코드 :

' Get excel object 
If Not FileHandling.setExcelObject(oXLApp) Then 
    failMessage = "You are editing a cell in excel, stop doing that!" 
    GoTo terminate 
End If 

' check if we need to close after 
closeExcelMy = FileHandling.ExcelOpen 

'See if we can open workbook 
If Not FileHandling.GetWorkbook(wbName, oXLApp, xlApp) Then 
    failMessage = "Failed to open workbook" 
    GoTo terminate 
End If 

oXLApp.Visible = True