goo blog サービス終了のお知らせ 

開発頭-kenken

写真付きで日記や趣味を書くならgooブログ

最近node.jsが気になってきました。

APIでJSONデータを取得する

2018-03-20 14:59:43 | エクセル・VBA

'--- メイン

Dim wk1, wk2 As Variant

strJson = LoadJsonFromDB("12345")

wk1 = Split(json, "")

wk2 = Split(wk1(1), "")

debug.print   "12345"  &  wk2(0) 

 

'--- JSON取得

Function LoadJsonFromDB(pCode As Variant) As String

  Dim XMLhttp As Object
  Dim myUrl As String
  myUrl = "http://aaa.co.jp/bbb?code=" & pCode

  Set XMLhttp = CreateObject("MSXML2.ServerXMLHTTP")
  XMLhttp.Open "GET", myUrl, False
  XMLhttp.setRequestHeader "Content-Type", "application/json"
  XMLhttp.send
  LoadJsonFromDB = XMLhttp.responseText
End Function

 

'--- 結果

 12345=abcde

 


IPアドレス取得

2018-03-05 15:36:43 | エクセル・VBA

procName = "IPアドレス取得"
Set accessLog = CreateObject("Scripting.Dictionary")

'--- IPアドレス
Set NetAdapters = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") _
.ExecQuery("Select * from Win32_NetworkAdapterConfiguration " & _
"Where (IPEnabled = TRUE)")

For Each objNic In NetAdapters 'ネットワークアダプターは、複数ある場合がある
  For Each strIPAddress In objNic.IPAddress 'IPは、複数割り当てられている場合がある
    resIP = strIPAddress
    Exit For ' 1回のみ
  Next
  Exit For ' 1回のみ
Next

 

debug.print  "IPアドレス=" & resIP

---結果---

IPアドレス=123.456.789.001


ショートカットキーセット

2018-02-23 10:19:06 | エクセル・VBA

'-------------------------------------------------------------------------------
' 処理  :ショートカットキーセット
' 概要  :エクセル起動中のショートカットキーをセットする
' 書式  :
' ShortcutKey:="j" → "crl+j"で起動する
' Macro:="openForm" → 起動するマクロ( call openForm
'-------------------------------------------------------------------------------
Sub setShortcutKey()
     Application.MacroOptions Macro:="openForm", ShortcutKey:="j"
End Sub
'-------------------------------------------------------------------------------
' 処理  :オープンフォーム
' 概要  :コントロールフォームを開く
'-------------------------------------------------------------------------------
Sub openForm()
     frm_Control.Show '--- コントロールフォームを開く
End Sub


連想配列

2018-02-23 10:07:29 | エクセル・VBA

    '---    宣言
    Dim myUser As Object
    Set myUser = CreateObject("Scripting.Dictionary")

    '---    作成
    myUser.Add "名前", "ディック・ベイヤー"
    myUser.Add "年齢", 87

    '---    使い方
    msgbox    "名前→" & myUser("名前") & " 年齢→" & myUser("名前")
 

    '---    全配列の取り出し
   Dim strMsg As String
   For Each var In myUser
        debug.print var &  ":" & myUser .Item(var) & vbCrLf
    Next var

 

★結果

名前:ディック・ベイヤー

年齢:87