Dim xls As Object
Dim wb As Object
Set xls = CreateObject("Excel.Application")
xls.DisplayAlerts = False
Set wb = xls.Workbooks.Open(FileName:=[Excelパス], ReadOnly:=True)
・・・(読込処理)・・・
wb.Close SaveChanges:=False
Set wb = Nothing
xls.DisplayAlerts = True
xls.Quit
Set xls = Nothing
UPDATE table1 SET
col1 = a.col1
, col2 = a.col2
FROM (SELECT .... FROM .... INNER JOIN ....) a
WHERE table1.id = a.id
とすると、
WITH句を使ったSQL文は
WITH a AS (
SELECT .... FROM .... INNER JOIN ....
)
UPDATE table1 SET
col1 = (SELECT col1 FROM a WHERE table1.id = a.id)
, col2 = (SELECT col2 FROM a WHERE table1.id = a.id)
Public Function CheckNetwork(ip As String) As Boolean
Dim wsh As Object
Dim buf As String
On Error GoTo ErrCheck
Set wsh = CreateObject("WScript.Shell")
wsh.Run "%ComSpec% /c ping -n 1 " & ip & " | clip ", 0, True
buf = GetObject("\" _
, "htmlfile").ParentWindow.ClipboardData.GetData("text")
If InStr(buf, "ラウンド トリップの概算時間") > 0 Then
CheckNetwork = True
End If
Exit Function
ErrCheck:
err.clear
End Function
Sub ProtectSheet
With ws
If Not .ProtectContents Then 'ロックされていないときだけロック処理
.Protect Password:="password"
, DrawingObjects:=True
, Contents:=True
, Scenarios:=True _
, AllowFiltering:=True 'ここでフィルターOKにする
End If
End With
End Sub
以下は試していないけれど、これでもOKらしい。
Sub ProtectSheet2
With ws
If Not .ProtectContents Then 'ロックされていないときだけロック処理
.Protect Password:="password"
, DrawingObjects:=True
, Contents:=True
, Scenarios:=True _
, userInterfaceOnly:=True
End If
.EnableAutoFilter = True
End With
End Sub
'ローカルならTrue、ネットワークならFalse
Public Function CheckLocal(filepath as String) As Boolean
Dim cap As String
Dim fso As Object
Dim obj As Object
'先頭が\なら確実にネットワーク
cap = Left(filepath, 1)
If cap = "\" Then
Exit Function
End If
'ドライブ割当のローカル/サーバ確認
Set fso = CreateObject("Scripting.FileSystemObject")
For Each obj In fso.Drives
If obj.DriveLetter = cap Then
If obj.DriveType = 3 Then
Else
CheckLocal = True
End If
Exit Function
End If
Next
'ここまで来たらどこかは不明
End Function