Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Last active November 10, 2021 14:33
Show Gist options
  • Save pandanote-info/2bc9f6c607bbafa5a0b7878e320b093e to your computer and use it in GitHub Desktop.
Save pandanote-info/2bc9f6c607bbafa5a0b7878e320b093e to your computer and use it in GitHub Desktop.
ExcelのシートからSQLite3のCREATE TABLE句が記述されたファイルを生成するためのExcelのアドインのThisWorkbookに記述するコード。
Option Explicit
Public WithEvents CreateTableStatementForSQLite3 As Application
Private Sub Workbook_Open()
Set CreateTableStatementForSQLite3 = Application
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set CreateTableStatementForSQLite3 = Nothing
End Sub
Private Sub DeleteControls()
On Error Resume Next
Application.CommandBars("Row").Controls("Create文を作る").Delete
Application.CommandBars("Cell").Controls("選択したセルからCreate文を作る").Delete
On Error GoTo 0
End Sub
Private Sub Workbook_AddinUninstall()
DeleteControls
End Sub
Private Sub CreateTableStatementForSQLite3_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
DeleteControls
With Application.CommandBars("Row").Controls.Add(Before:=1)
.Caption = "Create文を作る"
.OnAction = "Create_CreateClause"
End With
If Target.Rows.Count = 1 Or Target.Columns.Count = 1 Then
With Application.CommandBars("Cell").Controls.Add(Before:=1)
.Caption = "選択したセルからCreate文を作る"
.OnAction = "Create_CreateClauseFromCells"
End With
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment