XLODBC
1
Driver=PostgreSQL Unicode;Server={IPアドレス等};Port={PortNo};Database={DB名};Uid={UserID};Pwd={Password};
SELECT TOP 100 * FROM batch_log ORDER BY create_date desc
SQLServer
XLODBC
1
Driver=SQL Server;Server={IPアドレス等};Uid={UserID};Pwd={Password};Database={DB名};Connect Timeout=15;
SELECT * FROM batch_log ORDER BY create_date desc LIMIT 1;
CREATE PROCEDURE csvToRows
@csv VARCHAR(MAX)
AS
BEGIN
DECLARE @exit_flg TINYINT = 0
DECLARE @i INT = 1
DECLARE @imax INT
DECLARE @buf VARCHAR(MAX)
BEGIN TRY
-- はじめにNULLや空白を回避
IF RTRIM(LTRIM(ISNULL(@csv,'')))=''
BEGIN
RAISERROR (N'NULLはダメ!', 18, 1)
END
CREATE TABLE #w_temp (
buf VARCHAR(MAX)
)
SET @buf = @csv
WHILE @exit_flg = 0
BEGIN
SET @buf = SUBSTRING(@buf, @i , LEN(@buf))
SET @imax = CHARINDEX(',', @buf)
IF @imax = 0
BEGIN
INSERT INTO #w_temp
SELECT SUBSTRING(@buf, 1, LEN(@buf))
SET @exit_flg = 1
END
ELSE
BEGIN
INSERT INTO #w_temp
SELECT SUBSTRING(@buf, 1, @imax - 1)
SET @i = @imax + 1
END
END
SELECT 'OK' AS result, NULL AS err_msg, buf FROM #w_temp
END TRY
BEGIN CATCH
SELECT 'NG' AS result, ERROR_MESSAGE() AS err_msg
END CATCH
END
'呼出元プロシージャ(または関数)の記載例
Load HogeForm
HogeForm.Show
If HogeForm.Tag = "1" Then
'(終了ボタン押下時の処理を記載)
Else
'(中止ボタン押下時の処理を記載)
End If
Unload HogeForm
'呼出先(HogeForm)の記載例
'終了ボタン押下
Private Sub ExitButton_Click()
HogeForm.Tag = "1"
HogeForm.Hide
End Sub
'中止ボタン押下
Private Sub CancelButton_Click()
HogeForm.Tag = "0"
HogeForm.Hide
End Sub
Dim rng As Range
Dim msg As String
Dim clear_flg As Boolean
'選択中のセルにコメントを追加していく
Set rng = ActiveCell
msg = "あいうえお"
clear_flg = False 'コメントを刷新するときはTrueに変える
On Error Resume Next
If Not rng.Comment Is Nothing Then
If clear_flg Then
rng.Comment.Text msg '刷新
Else
rng.Comment.Text rng.Comment.Text() & vbNewLine
& msg '追記
End If
Exit Sub
End If
'新しいコメントを追加する
With rng.AddComment(msg)
.Shape.TextFrame.Characters.Font.ColorIndex = 2 'フォントは白
.Shape.TextFrame.Characters.Font.Size = 9
.Shape.TextFrame.AutoSize = True
.Shape.Fill.ForeColor.RGB = RGB(0, 0, 0) '背景は黒
.Visible = True
End With
'整数(上限が5桁 -99999~99999はOK)
Dim rng As Range '対象セル
Dim res As Boolean '結果
Set rng = ActiveCell '選択しているセルをチェックする
Set reg = CreateObject("VBScript.RegExp")
With reg
.IgnoreCase = True '大文字小文字は関係ない
.Global = True '全体をチェック
.Pattern = "^[-]?[0-9]{1,5}$"
If .Test(rng.Value) Then
res = True
Exit Function
End If
End With
'実数(上限が5桁 -999.99~999.99はOK)
Dim rng As Range '対象セル
Dim res As Boolean '結果
Set rng = ActiveCell
Set reg = CreateObject("VBScript.RegExp")
With reg
.IgnoreCase = True
.Global = True
'整数の場合のチェック
.Pattern = "^[-]?[0-9]{1,3}$"
If .Test(rng.Value) Then
res = True
Exit Function
End If
'実数の場合のチェック
.Pattern = "^[-]?[0-9]{1,3}[.]{1,1}[0-9]{0,2}$"
If .Test(rng.Value) Then
res= True
Exit Function
End If
End With
そして、英数字のみ
'英数字のみ(上限が5桁で、半角のみ、大文字小文字OK)
Dim rng As Range '対象セル
Dim res As Boolean '結果
Set rng = ActiveCell
Set reg = CreateObject("VBScript.RegExp")
With reg
.IgnoreCase = True
.Global = True
.Pattern = "^[a-z0-9]{0,5}$"
If .Test(rng.Value) Then
res = True
Exit Function
End If
End With
Sub DeleteNamesExcludePrintX()
Dim ws As Worksheet
Dim nm As Name
' シート内の定義(Printから始まる名前定義は印刷設定なので除外)
For Each ws In ThisWorkbook.Worksheets
For Each nm In ws.Names
Debug.Print nm.NameLocal & ": " & nm.Name
If nm.Name Like "*Print_*" Then
Else
nm.Delete
End If
Next
Next
' ブック内の定義
For Each nm In ThisWorkbook.Names
Debug.Print "** " & nm.NameLocal & ": " & nm.Name
nm.Delete
Next
End Sub