Hi All,
I need your assistance. I have a spreadsheet that has a DocID (the unique docID of Notes document) and about 3 other fields. The 3 fields exist in the documents and have to be updated. In some cases, the field is blank, and in other cases, the fields contain old values that need to be replaced from the new spreadsheet. Each row in the spreadsheet will have DocID; Field1; Field2; Field3; Field4 – and will exist in the database (so no new docs need to be created).
But the code below does the update through a view, is there another way that I can run this code without a view? Let say run the agent through FTSearch. The name of the form I have is called Sales
Thanks for your help.
Sub Initialize
Dim xlFilename As String
xlFilename = Inputbox$("Enter the Complete Path of the Excel File to be imported", "Excel Import" , "c:\test.xls")
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView 'To import BW docs
Dim doc As NotesDocument
Dim s_key As String
Dim row As Integer
Dim written As Integer
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xlSheet As Variant
Set db = session.CurrentDatabase
'// Next we connect to Excel and open the file. Then start pulling over the records.
Set view = db.getview("All Docs")
Print "Connecting to Excel..."
Set Excel = CreateObject( "Excel.Application" )
Excel.Visible = False '// Don't display the Excel window
Print "Opening " & xlFilename & "..."
Excel.Workbooks.Open xlFilename '// Open the Excel file
Set xlWorkbook = Excel.ActiveWorkbook
'Set xlSheet = xlWorkbook.ActiveSheet
Set xlSheet = xlWorkbook.worksheets("Sales_Data")
Records:
row = 1 '// These integers intialize to zero anyway
written = 0
Print "Starting import from Excel file..."
While xlsheet.cells(row,1).value <> ""
Finish:
With xlSheet
Set doc = view.getdocumentbykey(Trim(.Cells(row, 1).Value))
If Not doc Is Nothing Then
doc.SalesDate = Trim(.Cells( row, 2).Value)
doc.ProductDate=Trim( .Cells(row, 3).Value)
doc. SalespersonTrim( .Cells(row, 4).Value)
Call doc.Save( False, True )
End If
row = row + 1
Print row
End With
Wend
Done:
Print "Disconnecting from Excel..."
xlWorkbook.Close False ' Close the Excel file without saving (we made no changes)
Excel.Quit ' Close Excel
Set Excel = Nothing ' Free the memory that we'd us
End Sub