Dim w As New NotesUIWorkspace ' needed for prompt Dim s As New NotesSession Dim db As NotesDatabase ' current db Dim gV As NotesView ' lookup view to export Dim pathVar As Variant ' export path Dim pathstr As String ' export path as string Dim gEC As NotesViewEntryCollection ' all groups in gV Dim gE As NotesViewEntry ' entry/doc in gEC Dim gDoc As NotesDocument ' doc being exported Dim gMembers As NotesItem ' doc Members field Dim pV As NotesView ' users view to get user e-mail Dim pDoc As NotesDocument ' user doc to get e-mail ' dims for export Dim ffilenum As Integer ' file handle to export file Dim tmpstr As String ' temp working string for manipulating values Dim flinestr As String ' line of text for export file Dim dtotal As Double ' counter total Dim dcurrent As Double ' counter current On Error GoTo SErrorHandler ' setup Set db = s.CurrentDatabase Set gV = db.Getview("Groups") If (gV Is Nothing) Then Print "Aborted. Missing group view." Exit Sub End If ' prompt for continue and path pathstr = "c:\temp\myexportfile.csv" pathVar = w.Prompt(PROMPT_OKCANCELEDIT,_ "Path for Group Export", "Please update the default path below and click OK to continue.", pathstr) If IsEmpty (pathVar) Then ' no path, abort Print "Aborted. No path or cancelled." Exit Sub Else ' update path If Not (CStr(pathVar) = "") Then pathstr = CStr(pathVar) End If End If ' get groups Set gEC = gV.Allentries If (gEC.Count = 0) Then ' no entries/docs, abort Print "Aborted. No entries/docs in view, " & gV.Name & "." Exit Sub End If ' start file ffilenum = FileOpenWrite(pathstr) If (ffilenum = 0 ) Then ' failure starting file Print "Unable to start file, " & pathstr & ". Aborted export." Exit Sub End If ' add labels flinestr = |"Group Name","Description","Type","E-mail","Members",| Call FileWriteLine(flinestr, ffilenum) ' prep counter flinestr="" dcurrent = 0 dtotal = gEC.Count ' loop through docs Set gE = gEC.Getfirstentry() While Not (gE Is Nothing) ' reset export line flinestr = "" tipster = “” ' have entry, get doc Set gDoc = gE.Document If Not (gDoc Is Nothing) Then ' add doc... ' ... do view name tmpstr = ReplaceChar(gDoc.ListName(0), |"|, |'|) tmpstr = ReplaceChar(tmpstr, |,|, | |) flinestr = |"| & tmpstr & |",| ' ... do description tmpstr = ReplaceChar(gDoc.ListDescription(0), |"|, |'|) tmpstr = ReplaceChar(tmpstr, |,|, | |) flinestr = flinestr & |"| & tmpstr & |",| ' ... do type tmpstr = ReplaceChar(gDoc.GroupType(0), |"|, |'|) tmpstr = ReplaceChar(tmpstr, |,|, | |) flinestr = flinestr & |"| & tmpstr & |",| ' ... do e-mail/internet address tmpstr = ReplaceChar(gDoc.InternetAddress(0), |"|, |'|) tmpstr = ReplaceChar(tmpstr, |,|, | |) flinestr = flinestr & |"| & tmpstr & |",| ' ... do members (as one really big column row) Set gMembers = gDoc.Getfirstitem("Members") If Not (gMembers Is Nothing) Then ' get name and then e-mail if possible ForAll mName In gMembers.Values ' get name If Not (mName ="") Then Set pDoc = pV.Getdocumentbykey(CStr(mName), True) If Not (pDoc Is Nothing) Then ' get e-mail tmpstr = pDoc.InternetAddress(0) tmpstr = ReplaceChar(tmpstr, |"|, |'|) If (tmpstr = "") Then ' try forwarding e-mail tmpstr = pDoc.MailAddress(0) tmpstr = ReplaceChar(tmpstr, |"|, |'|) End If If (tmpstr = "") Then ' use name tmpstr = CStr(mName) flinestr = flinestr & |"| & tmpstr & |",| Else ' use e-mail flinestr = flinestr & |"| & tmpstr & |",| End If Else ' pDoc nothing, add the member's name instead of e-mail tmpstr = CStr(mName) tmpstr = ReplaceChar(tmpstr, |"|, |'|) flinestr = flinestr & |"| & tmpstr & |",| End If Else ' no gMember value, skip End If ' loop End ForAll Else tmpstr = "" flinestr = flinestr & |"| & tmpstr & |",| End If Call FileWriteLine(flinestr, ffilenum) End If ' update progress bar Print PercentComplete( 25 , dcurrent, dtotal) dcurrent = dcurrent + 1 ' loop Set gE = gEC.Getnextentry(gE) Wend ' done writing, close file Call FileCloseWrite(ffilenum) Print "Execution done. Your file is at: " & pathstr & "." Exit Sub SErrorHandler: Print "Error: " & CStr(Err) & " " & Error$ & ", line: " & CStr(Erl) & "." End Sub Function FileOpenWrite(expfilenm As String ) As Integer Dim filenum As Integer ' filehandle Dim fname As String ' filename/filepath On Error GoTo FErrorHandler ' setup filepath filenum = FreeFile fname = expfilenm ' open up new file for write Open fname For Output As filenum ' return success as file handle FileOpenWrite = filenum Exit Function FErrorHandler: Print "(FileOpenWrite) Error. Info: " & Str ( Err ) & ": " & Error$ & " on line: " & CStr ( Erl ) & "
" FileOpenWrite = 0 Exit Function End Function Function FileWriteLine(linetext As String , filehandlenum As Integer ) As Integer ' writes a data line to file Print # filehandlenum, linetext FileWriteLine = 1 End Function Function FileCloseWrite(filehandlenum As Integer ) As Integer ' closes open file Close filehandlenum ' return success FileCloseWrite= 1 End Function Function ReplaceChar(origstring As String , subchar As String , newchar As String ) As String Dim szReturn As String ' the modified string to return Dim modstring As String ' inprogress modstring Dim index As Integer ' working variable showing where subchar is or is not in the origstring Dim sublen As Integer ' # of characters length of subchar ' takes an original string (origstring) and replaces all characters of subchar with newchar ' returns the modifed (if subchar was found) string back ' this is modification of the old one stored in the mindwatering support db in that this one supports multiple characters for subchar modstring = origstring sublen = Len (subchar) index = InStr ( 1 , modstring, subchar) If (sublen = 0) Then ' we have a nothing subchar so lets just return the original string ReplaceChar = origstring Exit Function End If If (index = 0 ) Then ' subchar was not found in origstring so we can return the original string ReplaceChar = origstring Exit Function End If While index <> 0 szReturn = Left$ (modstring, index - 1 ) szReturn = szReturn + newchar + Mid$ (modstring, index + sublen) modstring = szReturn index% = InStr ( 1 , modstring, subchar) Wend ReplaceChar = szReturn End Function Function PercentComplete(FTGDefault As Integer , FTGCurrent As Double , FTGTotal As Double ) As String %REM Purpose: Displays a percent complete progress indicator in the status bar. Not as useful for web printing as each bar would be on a new line. %END REM Dim FTGLength As Integer Dim FTGCount As Integer PercentComplete = Chr ( 127 ) FTGLength = (FTGCurrent*FTGDefault)/FTGTotal For FTGcount = 2 To FTGDefault + 1 If FTGCount <= FTGLength + 1 Then PercentComplete = PercentComplete + Chr ( 127 ) Else PercentComplete = PercentComplete + "-" End If Next FTGcount PercentComplete = PercentComplete + Chr ( 127 ) + " " + CStr ( CInt ((FTGCurrent/FTGTotal)* 100 )) + "% Complete" End Function