Last active
February 17, 2021 03:03
-
-
Save jca02266/d96d77f8a51494854cf53df0eaf041b3 to your computer and use it in GitHub Desktop.
VBA Packager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' 利用手順 | |
| ' | |
| ' 事前準備 | |
| ' Excel等のMS Office アプリケーションにて | |
| ' オプション → セキュリティセンター → セキュリティセンターの設定 → マクロの設定 | |
| ' より、 | |
| ' □ VBAプロジェクト オブジェクト モデルへのアクセスを信頼する | |
| ' にチェックをつける | |
| ' | |
| ' 1. このテキストの内容を標準モジュールに貼り付ける | |
| ' 2. Immediate ウィンドウにて | |
| ' setup | |
| ' importall | |
| ' を実行する | |
| Sub setup() | |
| With ThisWorkbook.VBProject.vbcomponents.Add(1): .Name = "VBAPackager": .CodeModule.AddFromString "Option Explicit" & vbCrLf & "Sub Import(Name as String, Url As String)" & vbCrLf & "Dim body As String" & vbCrLf & "Dim whr As Object" & vbCrLf & "Set whr = CreateObject(""WinHttp.WinHttpRequest.5.1"")" & vbCrLf & "whr.Open ""GET"", Url, False" & vbCrLf & "whr.setRequestHeader ""Content-Type"", ""application/json""" & vbCrLf & "whr.send" & vbCrLf & "Select Case whr.Status" & vbCrLf & "Case 200, 202:" & vbCrLf & "body = whr.responseText" & vbCrLf & "Case Else:" & vbCrLf & "Err.Raise 10000 + whr.Status, Description:=whr.Status & "":"" & whr.responseText" & vbCrLf & "Exit Sub" & vbCrLf & "End Select" & vbCrLf & "Dim comp As Object" & vbCrLf & "Set comp = ThisWorkbook.VBProject.vbcomponents.Add(1)" & vbCrLf & "comp.Name = Name" & vbCrLf & "comp.CodeModule.AddFromString body" & vbCrLf & "End Sub" & vbCrLf: End With | |
| End Sub | |
| Sub ImportAll() | |
| VBAPackager.Import "hello", "https://gist.githubusercontent.com/jca02266/d96d77f8a51494854cf53df0eaf041b3/raw/b33686d599c3527902a9de434a15cc120088e1e6/sample.vba" | |
| End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub sample() | |
| Debug.Print "Hello, world!" | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment