LoginSignup
0
0

More than 3 years have passed since last update.

コピペ用VBAコード

Last updated at Posted at 2018-07-02
前提条件

ここに記載のプロシージャが必要です。
https://qiita.com/hayakawa_qiita/items/f783e42e4bcece87c1c0


'------------------------------------------------------
' ホットキー設定
'------------------------------------------------------
Public Sub StartOriginalHotkey()
    Application.OnKey "^%h", "ActionCtrlAltH"
    Application.OnKey "^%j", "ActionCtrlAltJ"
    Application.OnKey "^%;", "ActionCtrlAltSemicolon"
End Sub
Public Sub StopOriginalHotkey()
    Application.OnKey "^%h"
    Application.OnKey "^%j"
    Application.OnKey "^%;"
End Sub
Public Sub ActionCtrlAltH()
    Dim sheet As Worksheet
    Set sheet = Workbooks("~~.xlsx").Sheets("Sheet1")
    sheet.Shapes("わく").Copy
    ActiveSheet.Paste
End Sub
Public Sub ActionCtrlAltJ()
    Dim sheet As Worksheet
    Set sheet = Workbooks("~~.xlsx").Sheets("Sheet1")
    sheet.Shapes("こねくた").Copy
    ActiveSheet.Paste
End Sub
Public Sub ActionCtrlAltSemicolon()
    'rowIdx = ActiveCell.row
    'Rows(ActiveCell.row & ":" & ActiveCell.row + 3).Insert
End Sub


'------------------------------------------------------
' SQLログからSQL文組み立て
'------------------------------------------------------
Public Function HereSql(preparing As String, parameters As String)

    Dim sql As String
    sql = preparing
    Dim param As Variant
    For Each param In Split(parameters, ",")
        sql = Replace(sql, "?", toSqlValue(CStr(param)), , 1)
    Next
    HereSql = sql

End Function
Private Function toSqlValue(param As String)
    Dim sqlValue As String
    Dim dataValue As String
    Dim dataType As String

    Dim ms As Object
    Set ms = RegExp(Trim(param), "(.+)\((.+)\)$")
    Dim m As Object
    For Each m In ms
        dataValue = m.submatches(0)
        dataType = m.submatches(1)
    Next

    If dataType = "String" Then
        sqlValue = "'" & dataValue & "'"
    ElseIf dataType = "Date" Then

    Else
        sqlValue = dataValue
    End If
    toSqlValue = sqlValue
End Function

'------------------------------------------------------
' DB処理
'------------------------------------------------------
Private Sub ExexuteDBTask()

    Dim cn As Object
    Set cn = GetDBConnection("なんらかの接続文字列")

    Dim rs As Variant
    Set rs = CreateObject("ADODB.Recordset")

    Dim sql As String
    sql = "SELECT ~ "
    rs.Open sql, cn

    Dim recordCount As Long
    Do Until rs.EOF

        'なんらかのしょり

        recordCount = recordCount + 1

        rs.moveNext
    Loop

End Sub

0
0
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
0
0