{"id":2416,"date":"2022-06-11T01:57:12","date_gmt":"2022-06-10T16:57:12","guid":{"rendered":"http:\/\/oreoreki.gotdns.ch\/?p=2416"},"modified":"2022-06-11T01:59:38","modified_gmt":"2022-06-10T16:59:38","slug":"post-2416","status":"publish","type":"post","link":"http:\/\/oreoreki.gotdns.ch\/?p=2416","title":{"rendered":"VBA\u3067\u30b9\u30c6\u30ec\u30aa\u30b0\u30e9\u30e0\uff08\u7acb\u4f53\u8996\uff09\u3092\u63cf\u3044\u3066\u307f\u305f"},"content":{"rendered":"<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"750\" height=\"422\" src=\"https:\/\/www.youtube.com\/embed\/c2_EfCBNBsk?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=ja&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span><\/p>\n<div class=\"hcb_wrap\">\n<p>VBA\u3067\u30b9\u30c6\u30ec\u30aa\u30b0\u30e9\u30e0\uff08\u7acb\u4f53\u8996\/\u30de\u30b8\u30ab\u30eb\u30fb\u30a2\u30a4\uff09\u3092\u63cf\u3044\u3066\u307f\u305f<br \/>\n<span class=\"bold-red\">\u3053\u306e\u52d5\u753b\u306e\u30de\u30af\u30ed\u306fWindows11\/Office2013\u3067\u4f5c\u6210\u3057\u3066\u307e\u3059\u3002<br \/>\n<\/span><\/p>\n<h2><\/h2>\n<pre class=\"prism line-numbers lang-ts\" data-lang=\"TypeScript\"><code>#If Win64 Then\r\n    ' Excel \u304c64\u30d3\u30c3\u30c8\u7248\u306e\u5834\u5408\u306e\u95a2\u6570\u5b9a\u7fa9\u3067\u3059\u3002\r\n    Private Declare PtrSafe Function MessageBoxTimeoutA Lib \"User32.dll\" _\r\n        (ByVal hWnd As LongPtr, _\r\n        ByVal lpText As String, _\r\n        ByVal lpCaption As String, _\r\n        ByVal uType As VbMsgBoxStyle, _\r\n        ByVal wLanguageID As Long, _\r\n        ByVal dwMilliseconds As Long) As Long\r\n#Else\r\n    ' Excel \u304c32\u30d3\u30c3\u30c8\u7248\u306e\u5834\u5408\u306e\u95a2\u6570\u5b9a\u7fa9\u3067\u3059\u3002\r\n    Private Declare Function MessageBoxTimeoutA Lib \"User32.dll\" _\r\n        (ByVal hWnd As Long, _\r\n        ByVal lpText As String, _\r\n        ByVal lpCaption As String, _\r\n        ByVal uType As VbMsgBoxStyle, _\r\n        ByVal wLanguageID As Long, _\r\n        ByVal dwMilliseconds As Long) As Long\r\n#End If\r\nConst dots = \"\u30c9\u30c3\u30c8\"\r\nConst ptrn = \"\u56f3\u5f62\"\r\nConst strg = \"\u30b9\u30c6\u30ec\u30aa\u30b0\u30e9\u30e0\"\r\n\r\nConst dots_size = 64\r\nConst img_size_w = 300\r\nConst img_size_h = 150\r\n\r\nSub Macro1()\r\n    \r\n    'Sheet\u306e\u521d\u671f\u5316\r\n    MakeSheet dots\r\n    MakeSheet ptrn\r\n    MakeSheet strg\r\n    \r\n    Sheets(dots).Activate\r\n    Call make_dots\r\n    MessageBoxTimeoutA 0, \"\u30c9\u30c3\u30c8\u6a21\u69d8\u3092\u66f8\u3044\u305f\", \"\u30e1\u30c3\u30bb\u30fc\u30b8\", 1, 65536, 3 * 1000\r\n\r\n\r\n    Sheets(ptrn).Activate\r\n    MessageBoxTimeoutA 0, \"\u30d1\u30bf\u30fc\u30f3\u3092\u63cf\u304f\u305c\", \"\u30e1\u30c3\u30bb\u30fc\u30b8\", 1, 65536, 3 * 1000\r\n    Call make_img\r\n    \r\n    MessageBoxTimeoutA 0, \"\u30b9\u30c6\u30ec\u30aa\u30b0\u30e9\u30e0\u3092\u63cf\u304f\u305c\", \"\u30e1\u30c3\u30bb\u30fc\u30b8\", 1, 65536, 3 * 1000\r\n    Sheets(strg).Activate\r\n    Call make_autostereogram\r\n    MessageBoxTimeoutA 0, \"\u898b\u308c\", \"\u30e1\u30c3\u30bb\u30fc\u30b8\", 1, 65536, 3 * 1000\r\n\r\nEnd Sub\r\n\r\nFunction make_dots()\r\n    For r = 1 To dots_size\r\n        For c = 1 To dots_size\r\n            '\u4e71\u6570\u3092\u767a\u751f\u3055\u305b\u30bb\u30eb\u306b\u5024\u3092\u5165\u308c\u3001\u80cc\u666f\u8272\u3092\u305d\u306e\u4e71\u6570\u3067\u5857\u308b\r\n            g = Int(Rnd * 255)\r\n            Sheets(dots).Cells(c, r).Value = g\r\n            Sheets(dots).Cells(c, r).Interior.Color = RGB(g, g, g)\r\n        Next\r\n    Next\r\nEnd Function\r\n\r\nFunction make_img()\r\n    'Sheet2\u306b\r\n    '\u534a\u5f84\u304c\u9ad8\u3055\u306e1\/3\u306e\u5186\u3092\u63cf\u304f\r\n    For r = 1 To img_size_w\r\n        For c = 1 To img_size_h\r\n            If (r - img_size_w \/ 2) ^ 2 + (c - img_size_h \/ 2) ^ 2 < (img_size_h \/ 3) ^ 2 Then\r\n                Sheets(ptrn).Cells(c, r).Value = 1\r\n                Sheets(ptrn).Cells(c, r).Interior.Color = RGB(0, 0, 0)\r\n            Else\r\n                Sheets(ptrn).Cells(c, r).Value = 0\r\n            End If\r\n        Next\r\n        '\u4e0b\u5074\u306b\u5883\u754c\u7dda\u3092\u3064\u3051\u308b\r\n        Sheets(ptrn).Cells(img_size_h + 1, r).Interior.Color = RGB(255, 0, 0)\r\n    Next\r\nEnd Function\r\n\r\nFunction make_autostereogram()\r\n    \r\n    shift_amplitude = 0.15\r\n    For r = 1 To img_size_w\r\n        For c = 1 To img_size_h\r\n            If r <= dots_size Then\r\n                '\u306f\u3058\u3081\u306e64(dots_size)\u30bb\u30eb\u306f\u30c9\u30c3\u30c8\u30d1\u30bf\u30fc\u30f3\u3092\u305d\u306e\u307e\u307e\u30b3\u30d4\u30fc\r\n                Sheets(strg).Cells(c, r).Value = Sheets(dots).Cells(c Mod dots_size + 1, r).Value\r\n            Else\r\n                '\u56f3\u5f62\u30d1\u30bf\u30fc\u30f3\u304c\u91cd\u306a\u3089\u306a\u3044\u3068\u3053\u308d\u306f64\u5217\u524d\u3068\u540c\u3058\u8272\u306b\u3059\u308b\r\n                '\u56f3\u5f62\u30d1\u30bf\u30fc\u30f3\u3068\u91cd\u306a\u308b\u3068\u3053\u308d\u306f\u300164-\u03b1\u5217\u524d\u3068\u540c\u3058\u8272\u306b\u3059\u308b\u3002\u3053\u308c\u3067\u6a21\u69d8\u304c\u305a\u308c\u308b\u306f\u305a\u3002\r\n                shift = Int(Sheets(ptrn).Cells(c, r).Value * shift_amplitude * dots_size)\r\n                Sheets(strg).Cells(c, r).Value = Sheets(strg).Cells(c, r - dots_size + shift).Value\r\n            End If\r\n            '\u30bb\u30eb\u80cc\u666f\u8272\u306b\u30bb\u30eb\u5024\u306e\u8272\u3092\u306c\u308b\r\n            g = Sheets(strg).Cells(c, r).Value\r\n            Sheets(strg).Cells(c, r).Interior.Color = RGB(g, g, g)\r\n            DoEvents\r\n        Next\r\n    Next\r\n    Range(Sheets(strg).Cells(1, 1), Sheets(strg).Cells(img_size_w, img_size_h)).ClearContents\r\nEnd Function\r\nFunction MakeSheet(xMakeSheet As String)\r\n    '\u65e2\u5b58\u306e\u30b7\u30fc\u30c8\u3092\u524a\u9664\r\n    Application.DisplayAlerts = False ' \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u975e\u8868\u793a\r\n    If ExistsSheet(xMakeSheet) Then Sheets(xMakeSheet).Delete\r\n    Application.DisplayAlerts = True ' \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\r\n    '\u30b7\u30fc\u30c8\u3092\u8ffd\u52a0\r\n    Sheets.Add After:=Sheets(Sheets.Count)\r\n    ActiveSheet.Name = xMakeSheet\r\n    '\u30b7\u30fc\u30c8\u3092\u795e\u30a8\u30af\u30bb\u30eb\u65b9\u773c\u7d19\u306b\u3059\u308b\r\n    px = 3\r\n    Cells.ColumnWidth = px * 0.15\r\n    Cells.RowHeight = px * 1.5\r\nEnd Function\r\nFunction ExistsSheet(bName As String)\r\n    Dim ws As Variant\r\n    ExistsSheet = False\r\n    '\u5168\u30b7\u30fc\u30c8\u7e70\u308a\u8fd4\u3059\r\n    For Each ws In Sheets\r\n        If LCase(ws.Name) = LCase(bName) Then\r\n            ExistsSheet = True ' \u30b7\u30fc\u30c8\u304c\u5b58\u5728\u3057\u305f\r\n            Exit Function\r\n        End If\r\n    Next\r\nEnd Function\r\n\r\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>VBA\u3067\u30b9\u30c6\u30ec\u30aa\u30b0\u30e9\u30e0\uff08\u7acb\u4f53\u8996\/\u30de\u30b8\u30ab\u30eb\u30fb\u30a2\u30a4\uff09\u3092\u63cf\u3044\u3066\u307f\u305f \u3053\u306e\u52d5\u753b\u306e\u30de\u30af\u30ed\u306fWindows11\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2418,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34],"tags":[],"class_list":["post-2416","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vba"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/oreoreki.gotdns.ch\/wp-content\/uploads\/sites\/2\/2022\/06\/vba-1.jpg","jetpack_shortlink":"https:\/\/wp.me\/p9WqRX-CY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2416"}],"version-history":[{"count":1,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2416\/revisions"}],"predecessor-version":[{"id":2417,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2416\/revisions\/2417"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/media\/2418"}],"wp:attachment":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2416"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}