LoginSignup
8
11

More than 5 years have passed since last update.

VBAでオブジェクトを戻り値としてセットする方法。

Posted at

備忘録として残します。

■やり方

Set 関数名 = オブジェクトで戻り値にセットできます。

Private Function testFunc() As Object 'または As Variant
    Set obj = CreateObject("Scripting.Dictionary")
    'testFunc = obj 'NG
    Set testFunc = obj 'OK
End Function

関数の呼び出し元も戻り値はSetで受け取らないといけません。

Private Function main()
    Set returnObj = testFunc()
End Function

■余談

Setなくてもフレキシブルに渡してやれとか受け取ってくれとか思いますが、もうVBにキレるのは疲れました。

8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11