WindowsAPIã®MessageBoxãVBAã®MsgBoxã¨å¤§ããéãã®ã¯ãã¦ã¤ã³ãã¦ãã³ãã«ãæå®ã§ãããã¨ã§ããã
VBAã®MsgBoxã ã¨ã¡ãã»ã¼ã¸ããã¯ã¹ã¯å¿
ãã¨ã¯ã»ã«å´ã§è¡¨ç¤ºããã¦ãã¾ãã
ä¾ãã°ãWindowsAPIã§ä»ã®ã¢ããªãæä½ãã¦ãã¦ã¨ã¯ã»ã«ä»¥å¤ã®ã¦ã¤ã³ãã¦ãã¢ã¯ãã£ãã«ãªã£ã¦ãããããã®ã¡ãã»ã¼ã¸ã¯è¡¨ç¤ºãããªãã
ã¿ã¹ã¯ãã¼ã®ã¨ã¯ã»ã«ã¢ã¤ã³ã³ãç¹æ»
ãã¦ãèªåã§ã¨ã¯ã»ã«ãã¢ã¯ãã£ãã«ãã¦åãã¦ãã¡ãã»ã¼ã¸ããã¯ã¹ã表示ãããã®ã ã
ãã®è¾ºãã¯MsgBoxã®å®è¡åã«ãSetForegroundWindow Application.Hwndããæãã§ããã°ã¨ãããã対å¿ã¯ã§ããã
ããã©ãçµå±ã¯VBAã«ããã¨ã¯ã»ã«ããã®ã¡ãã»ã¼ã¸ããã¯ã¹ãªã®ã§ã表示ä½ç½®ã¯ã¨ã¯ã»ã«ã®ã¦ã¤ã³ãã¦ä¸å¤®ã¨ãªãã
ä¸æ¹ã®WindowsAPIã«ããMessageBoxãªããå¼æ°ã§ã¦ã¤ã³ãã¦ãã³ãã«ãæå®ã§ããã
ãããä»ã®ã¦ã¤ã³ãã¦ãæä½ãã¦ããæä¸ã«è¡¨ç¤ºããããã¡ãã»ã¼ã¸ã§ããã°ããã®ã¦ã¤ã³ãã¦ãã³ãã«ãæå®ãã¦ããã°ãããã¦ã¼ã¶ããªãã£ã®é«ãããã°ã©ã ã«ãªãã¨ã¯æããªãã ãããï¼
ããããåä½ã«ãã£ã¦WindowsAPIã®ãMessageBoxãã¨VBAã®ãMsgBoxãã使ãåããã®ã¯é¢åã§ããã
ãªã«ããå®æ°ãç°ãªãã
ãã®å®æ°ã«é¢ããé¨åãã§ããã ãVBAã«å¯ãããã¨ããã®ãä»åã®è©¦ã¿ã ã
ã¨ããããã§æ©éã³ã¼ããæ示ããã
ãªããå種APIã¨å®æ°ã®å®£è¨ã¯çç¥ãã¦ããã
Function ShowMessageBox(btn As Long, ico As Long, sText As String, sCap As String, Optional hWnd As LongPtr = 0, Optional isSysModal As Boolean = True) As Long SetForegroundWindow hWnd Dim uType As Long Select Case btn Case vbOKOnly uType = MB_OK Case vbOKCancel uType = MB_OKCANCEL Case vbYesNo uType = MB_YESNO Case vbYesNoCancel uType = MB_YESNOCANCEL End Select Select Case ico Case vbInformation uType = uType Or MB_ICONINFORMATION Case vbExclamation uType = uType Or MB_ICONEXCLAMATION Case vbQuestion uType = uType Or MB_ICONQUESTION Case vbCritical uType = uType Or MB_ICONSTOP End Select If isSysModal Then uType = uType Or MB_SYSTEMMODAL Dim ret As Long ret = MessageBox(hWnd, sText, sCap, uType) Select Case ret Case IDOK ShowMessageBox = vbOK Case IDCANCEL ShowMessageBox = vbCancel Case IDYES ShowMessageBox = vbYes Case IDNO ShowMessageBox = vbNo End Select End Function
è¦ããã«APIã®å®æ°ã¨VBAã®å®æ°ãç¸äºå¤æãã¦ãå¼æ°ã¨æ»ãå¤ãã¨ãã«VBAã®MsgBoxã¨åãã«ãã¦ããã ãã§ããã
æ©è½ã¨ãã¦ã¯æä½éã ãããã
ä¸è¨ã®ãµã¤ããåèã«å¼æ°ãå¢ãããªã©ãã¦ããæè»ã«å¯¾å¿ã§ããã¡ãã»ã¼ã¸ããã¯ã¹é¢æ°ãä½ãã®ã楽ãããããããªãã