【VBScript】キー入力検知 VBAマクロ起動

Option Explicit

on error resume next

Dim Excel
Dim strFunction
Dim FilePath
Dim app

Set Excel = CreateObject("Excel.Application")

FilePath = "C:\Users\ya570\Desktop\特定検索リニューアルテスト.xls"

Set app = CreateObject("Excel.Application")

app.Visible = true
app.Workbooks.Open FilePath


Do While true

	If CheckKey(&H1B) = true Then
		
		
		Exit Do

	End If



	If CheckKey(Asc("A")) = true Then
		
		app.Run "Module1.test"

	End If

	WScript.Sleep 100

Loop




Function CheckKey(Key)

	strFunction = "CALL(""user32.dll"", ""GetKeyState"", ""JJ"", " & key & ")"
	CheckKey = (Excel.ExecuteExcel4Macro(strFunction) And &h8000) <> 0

End Function

いいなと思ったら応援しよう!