|
|
Question : Automatic Export to Excel to a network drive
|
|
I am using the export to excel agent available on lotus sandbox to export some views,this works nicely, select the documents and it does the rest, now I need to automate this process and have the view exported daily at 5am how can I make this agent do this or is there a better way and will it work to a network drive? The agent now opens excel and lets me then save the file, I need it to just save the data to the network drive so it is available to other programs.....
|
Answer : Automatic Export to Excel to a network drive
|
|
Check this code for Schedule Export to Excel: Dim Session As New NotesSession Dim db As NotesDatabase Dim dataview As NotesView Dim datadoc As NotesDocument Dim maxcols As Integer
Dim ViewString As String
Set db = session.CurrentDatabase
ViewString= ""
Set dataview = db.getview(ViewString)
Dim xlApp As Variant Dim xlsheet As Variant Dim rows As Integer Dim cols As Integer
rows = 1 cols = 1 maxcols= dataview.columncount
Set xlApp = CreateObject("Excel.Application") xlApp.StatusBar = "Creating WorkSheet. Please be patient..." xlApp.Visible = True xlApp.Workbooks.Add xlApp.ReferenceStyle = 2 Set xlsheet = xlApp.Workbooks(1).Worksheets(1) xlsheet.Name = "Export From Notes" ' ViewString
xlApp.StatusBar = "Creating Column Heading. Please be patient..."
For x=1 To maxcols xlsheet.Cells(rows,cols).Value = dataview.columns(x-1).title cols = cols + 1 Next
Set datadoc = dataview.getfirstdocument Dim fitem As NotesItem cols=1 rows=2 Do While Not (datadoc Is Nothing) For x=1 To maxcols With dataview.Columns(x-1) If .isField Then xlsheet.Cells(rows,cols).Value = datadoc.GetItemValue(.itemname) Elseif .isFormula Then If .formula="@IsExpandable" Then xlsheet.Cells(rows,cols).Value = "" Else xlsheet.Cells(rows,cols).Value = Evaluate(.formula,datadoc) End If End If End With cols=cols+1 Next xlApp.StatusBar = "Importing Notes Data - Document " rows=rows+1 cols=1 Set datadoc = dataview.getnextdocument(datadoc) Loop
xlApp.Rows("1:1").Select xlApp.Selection.Font.Bold = True xlApp.Selection.Font.Underline = True xlApp.Range(xlsheet.Cells(1,1), xlsheet.Cells(rows,maxcols)).Select xlApp.Selection.Font.Name = "Arial" xlApp.Selection.Font.Size = 9 xlApp.Selection.Columns.AutoFit With xlApp.Worksheets(1) .PageSetup.Orientation = 2 .PageSetup.centerheader = "Report - Confidential" .Pagesetup.RightFooter = "Page &P" & Chr$(13) & "Date: &D" .Pagesetup.CenterFooter = "" End With xlApp.ReferenceStyle = 1 xlApp.Range("A1").Select xlApp.StatusBar = "Importing Data from Lotus Notes Application was Completed." xlapp.activeworkbook.saveas "" xlapp.quit
'Send an email with attached xls file Dim MRKnotice As NotesDocument Dim RTItem As NotesRichTextItem Set MRKnotice = New NotesDocument(db) MRKnotice.Form = "Email Notification" MRKnotice.SendTo = "someone@somewhere" 'MRKnotice.CopyTo = "someone@somewhere" 'MRKnotice.BlindCopyTo = "someone@somewhere" MRKnotice.SentBy = "Whomever" MRKnotice.Subject = "Whatever" Set RTItem = MRKnotice.CreateRichTextItem("Body") Call RTItem.EmbedObject(Embed_Attachment, "", "") Call MRKnotice.Send(True)
'this copies, renames and deletes the newly created file so there will be no file contention on next running of agent
Dim filePath As String Dim strFileDate As String filePath = ""
'Our agent ran weekly or daily so this is enough to make the file name unique strFileDate = Format$(Today, "MMDDYYYY") Filecopy filePath, "c:\notes\"&ViewString & strFileDate & ".xls" Kill filePath
|
|
|
|
|