Option Explicit
Private Sub CommandButton1_Click()
Dim Ans, session, db, View, doc, i, strShtName, Value01, Value02
Ans = MsgBox("実行しますか?", vbYesNo, "実行確認")
If Ans = vbNo Then Exit Sub
Set session = CreateObject("Notes.NotesSession")
'##### アクセスするデータベースのサーバー名とファイルパス
Set db = session.GetDatabase("server", "dir\file.nsf")
'##### ビューを取得
Set View = db.getView("view01")
i = 2
Set strShtName = ActiveSheet
Set doc = View.GetFirstDocument
Do Until doc Is Nothing
Value01 = doc.GetItemValue("DB_Value01")
Value02 = doc.GetItemValue("DB_Value02")
strShtName.Cells(i, 2) = Value01(0)
strShtName.Cells(i, 3) = Value02(0)
Set doc = View.GetNextDocument(doc)
i = i + 1
Loop
strShtName.Range(Cells(2, 1), Cells(i, 3)) _
.Sort Key1:=strShtName.Cells(1, 3), order1:=xlAscending, _
Key2:=strShtName.Cells(1, 2), order2:=xlAscending
MsgBox "完了"
End Sub
|