2017-12-20 65 views
2

excelが編集モードであるかどうかを調べたいと思っていますが、これはthreadを見て修正しようとしましたが、編集モードでは、それを実行して終了編集モードはまだ編集モードであると言い、それを再実行します。それはであることを把握することもひどい長い(15秒)をとります。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 

注意編集モード...

+0

。 [MSDNのApplication.Interactiveプロパティ](https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/application-interactive-property-excel)をチェックします。 –

+0

'exapp.Interactive = False'を削除してやり直すことはできますか? 'On Error GoToが終了する 'の後のもの? – Vityata

+0

うーん、私はそれを取得しない - メッセージを生成しているコードはどこにあるのですか? "あなたはExcelでセルを編集しています。それは明らかにOfficeに組み込まれたメッセージではないため、追加したものから来ている必要があります。それを見つけて、あなたが_easily_見つけることができます**どのように**それは、セルが編集中であることを検出しています。モジュールとCTRL + Fを押すだけで簡単に見つけることができます。**プロジェクト**全体を検索し、そのフレーズの一部を検索することを選択します。 – ashleedawg

答えて

1

ここに作業コードがあります:

'********************************************************************** 
'********* 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 

私は、このようにいくつかの手順から呼び出す上記のコード:私は `インタラクティブproperty`がここで使用する1つであるとは思わない

' 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 
関連する問題