2015-02-09 121 views
2

我正在調查將數據從Notes數據庫直接拖入Excel中,因爲我們的財務人員正在手動重新輸入數字a.t.m. 這是我到目前爲止的代碼:從Excel VBA訪問Lotus Notes數據庫 - 如何獲取COLUMNVALUES?

子notesBB()

Const DATABASE = 1247 
Dim r As Integer 
Dim i As Integer 
Dim c As Integer 
Dim db As Object 
Dim view As Object 
Dim Entry As Object 
Dim nav As Object 
Dim Session As Object 'The notes session 
Dim nam As Object 
Dim val As Variant 
Dim v As Double 
Dim items As Object 
Set Session = CreateObject("Lotus.NotesSession") 
Call Session.Initialize 
Set nam = Session.CreateName(Session.UserName) 
user = nam.Common 
Set db = Session.getdatabase("MSPreston", "Billbook1415.nsf") 
Set view = db.GetView("By Month\By Dept") 
view.AutoUpdate = False 
Set nav = view.CreateViewNav 
Set Entry = nav.GetFirst 
val = Entry.childcount    
val = Entry.ColumnValues(6)   ' this doesn't work 
Set items = Entry.ColumnValues  'from a suggestion on the net 
val = items(6)      'this doesn't work either 
MsgBox (val) 
End Sub 

錯誤是「對象變量或帶塊變量未設置」

惱人的事情是,我可以看到i的值想在ExcelVBA調試窗口中...所以我不能離得很遠。我猜想它如何訪問項目的數組妥善

回答

2

答案是聲明一個變量數組,並直接分配給它...

Sub notesBB() 
Const DATABASE = 1247 
Dim r As Integer 
Dim i As Integer 
Dim db As Object 
Dim view As Object 
Dim Entry As Object 
Dim nav As Object 
Dim Session As Object 'The notes session 
Dim nam As Object  ' notes username 
Dim v() As Variant  ' to hold the subtotal values 
Dim bills(12, 16)  ' 12 months, 16 departments 
r = 1 
Worksheets(1).Range("A1:z99").Clear 
Set Session = CreateObject("Lotus.NotesSession") 'Start a session to notes 
Call Session.Initialize 
Set nam = Session.CreateName(Session.UserName) 
user = nam.Common 
Set db = Session.getdatabase("MSPreston", "Billbook1415.nsf") 
Set view = db.GetView("By Month\By Dept") 
view.AutoUpdate = False 
Set nav = view.CreateViewNav 
Set Entry = nav.GetFirst 
Do Until Entry Is Nothing 
If Entry.isCategory Then 
    r = r + 1 
    v = Entry.ColumnValues 
    For i = 1 To 16 
    bills(v(0), i) = v(4 + i) 
    Cells(4 + r, 2 + i) = bills(v(0), i) 
    Next 
End If 
Set Entry = nav.getNextCategory(Entry) 
DoEvents 
Loop 
End Sub 

這段代碼只是通過16個部門提取12個月(行) (cols)從Notes視圖開票並使用它們填充Excel範圍。當你知道(發現)如何時很容易!

相關問題