Skip to content

Instantly share code, notes, and snippets.

@yujihamaguchi
Last active August 29, 2015 14:05
Show Gist options
  • Save yujihamaguchi/7cc6efaf55263b980b9f to your computer and use it in GitHub Desktop.
Save yujihamaguchi/7cc6efaf55263b980b9f to your computer and use it in GitHub Desktop.
[VBA] VBAからHaskell処理を使う
-- Haskell
import System
import Text.ParserCombinators.Parsec
main = do args <- getArgs
run parens (head args)
run :: Show a => Parser a -> String -> IO()
run p cs = case (parse p "" cs) of
Left e -> print e
Right x -> print x
parens :: Parser Int
parens = do char '('
n <- parens
char ')'
m <- parens
return (max (n + 1) m)
<|> return 0
-- VBA
'"C:\script\pDepth"を実行する
Function pDepth(ByRef trgt As Range) As String
pDepth = execCmmnd("pDepth " & trgt.Value)
End Function
'指定された外部コマンドを実行し、そのコマンドの標準出力を返す
Function execCmmnd(cmmnd As String) As String
Dim WSH, wExec As Variant
Set WSH = CreateObject("WScript.Shell")
Set wExec = WSH.Exec("cmd /q /c " & cmmnd)
Do While wExec.Status = 0
DoEvents
Loop
execCmmnd = wExec.StdOut.ReadAll
Set wExec = Nothing
Set WSH = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment