xlAbort

適用対象: Excel 2013 | Office 2013 | Visual Studio

システム内の他のタスクにプロセッサを生成し、ユーザーが Esc を押してマクロを取り消したかどうかを確認します。 ブックの再計算中にユーザーが Esc が押した場合は、この関数を呼び出すことによってワークシート関数内で検出することもできます。

Excel12(xlAbort, LPXLOPER12 pxRes, 1, LPXLOPER12 pxRetain);

パラメーター

pxRetain (xltypeBool)

(省略可能)。 FALSE の場合、この関数は中断状態を確認し、保留中の中断をすべて解除します。 これにより、ユーザーは中断状態を無視して続行できます。 この引数が省略されているか、TRUE の場合、関数はユーザーによる中止を解除せずに確認します。

プロパティ値/戻り値

ユーザーが Esc を押した場合は、TRUE (xltypeBool) が返されます。

頻繁な呼び出しが必要な場合

時間のかかる関数やコマンドでは、この関数を頻繁に呼び出して、プロセッサをシステム内の他のタスクに生成する必要があります。

微妙な表現を避ける

ユーザー インターフェイスでは "Abort" という用語を使用しないようにします。 代わりに "Cancel"、"Halt"、"Break"、"Stop" の使用を検討してください。

次のコードは、1 分が経過するまで、またはユーザーが Esc を押すまで、シート上でアクティブなセルを繰り返し移動します。 関数 xlAbort を呼び出すこともあります。 これによりプロセッサが生成され、共同でのマルチタスキングが容易になります。

\SAMPLES\GENERIC\GENERIC.C

int WINAPI fDance(void)
{
   DWORD dtickStart;
   XLOPER12 xAbort, xConfirm;
   int boolSheet;
   int col=0;
   XCHAR rgch[32];
//
// Check what kind of sheet is active. If it is a worksheet or macro
// sheet, this function will move the selection in a loop to show
// activity. In any case, it will update the status bar with a countdown.
//
// Call xlSheetId; if that fails the current sheet is not a macro sheet or
// worksheet. Next, get the time at which to start. Then start a while
// loop that will run for one minute. During the while loop, check if the
// user has pressed ESC. If true, confirm the abort. If the abort is
// confirmed, clear the message bar and return; if the abort is not
// confirmed, clear the abort state and continue. After checking for an
// abort, move the active cell if on a worksheet or macro. Then
// update the status bar with the time remaining.
//
// This block uses TempActiveCell12(), which creates a temporary XLOPER12.
// The XLOPER12 contains a reference to a single cell on the active sheet.
// This function is part of the framework library.
//
   boolSheet = (Excel12f(xlSheetId, 0, 0) == xlretSuccess);
   dtickStart = GetTickCount();
   while (GetTickCount() < dtickStart + 60000L)
   {
      Excel12f(xlAbort, &xAbort, 0);
      if (xAbort.val.xbool)
      {
         Excel12f(xlcAlert, &xConfirm, 2,
           TempStr12(L"Are you sure you want to cancel this operation?"),
              TempNum12(1));
         if (xConfirm.val.xbool)
         {
            Excel12f(xlcMessage, 0, 1, TempBool12(0));
            return 1;
         }
         else
         {
            Excel12f(xlAbort, 0, 1, TempBool12(0));
         }
      }
      if (boolSheet)
      {
         Excel12f(xlcSelect, 0, 1,
            TempActiveCell12(0,(BYTE)col));
         col = (col + 1) & 3;
      }
      wsprintfW(rgch,L"0:%lu",
         (60000 + dtickStart - GetTickCount()) / 1000L);
      Excel12f(xlcMessage, 0, 2, TempBool12(1), TempStr12(rgch));
   }
   Excel12f(xlcMessage, 0, 1, TempBool12(0));
   return 1;
}

関連項目

DLL または XLL からのみ呼び出し可能な C API 関数