lcFolderName = "text weather" llFolderExists = .F. FOR EACH loFolder IN myFolder.Folders IF loFolder.Name = lcFolderName llFolderExists = .T. lcTWfolder = loFolder EXIT ENDIF ENDFOR IF NOT llFolderExists lcTWfolder = myFolder.Folders.ADD("text weather") ? "Creating folder" ENDIF fldContacts = lcTWfolder.Items myItems = fldContacts.RESTRICT("[CompanyName] = 'Texting'") FOR i=myItems.Count TO 1 STEP -1 myItem = myItems.Item(i) IF (myItem.CLASS = 40) myItem.Delete() ENDIF ENDFOR>I have the import of contacts from Excel working great but I would like to be able to find a contact folder named 'text weather' and create it if it does not exist. myNewFolder = myFolder.Folders.ADD("text weather") creates the folder but errors if it is not there. On the other hand, fldContacts = myFolder.Folders("text weather").Items opens the correct folder by errors if it does not exist.
>m.excelcopy = "TextImport.xls" >open_excel_load_outlook(m.excelcopy) > >FUNCTION open_excel_load_outlook > PARAMETERS m.excelFileName > SET SAFETY OFF > IF NOT FILE(m.excelFileName) > WAIT WINDOW (m.excelFileName + " was not found.") > RETURN .F. > ENDIF > > myOlApp = CREATEOBJECT("Outlook.Application") > nms = myOlApp.GetNamespace("MAPI") > myFolder = nms.GetDefaultFolder(10) > ON ERROR DO exit_program >&& myNewFolder = myFolder.Folders.ADD("text weather") > fldContacts = myFolder.Folders("text weather").Items > myItems = fldContacts.RESTRICT("[CompanyName] = 'Texting'") > FOR EACH myItem IN myItems > IF (myItem.CLASS = 40) >&& MESSAGEBOX(myItem.FULLNAME + ": " + TTOC(myItem.LastModificationTime) + ": " + myItem.CompanyName) > myItems.REMOVE (1) > ENDIF > NEXT > xlApp = CREATEOBJECT("Excel.Application") > wkb = xlApp.Workbooks.OPEN(m.excelFileName) > WKS = wkb.Sheets(1) > WKS.ACTIVATE >*!* xlApp.VISIBLE = .T. >&& xlApp.Workbooks(1).Worksheets(1).ACTIVATE > xlApp.RANGE("A2").SELECT > > lngRows = WKS.UsedRange.ROWS.COUNT > DO WHILE LEN(xlApp.activecell.offset(0,3).VALUE) > 0 >&& Debug.Print "On Row " & lngCurrentRow > strName = xlApp.activecell.offset(0,5).VALUE > strEMail = xlApp.activecell.offset(0,4).VALUE > IF LEN(xlApp.activecell.offset(0,5).VALUE ) > 0 THEN >&& MESSAGEBOX("Name : " + xlApp.activecell.offset(0,5).VALUE ) > con = fldContacts.ADD(2) > con.FULLNAME = xlApp.activecell.offset(0,5).VALUE > con.FileAs = xlApp.activecell.offset(0,5).VALUE >*!* con.Email1Address = xlApp.activecell.offset(0,4).value > con.FirstName = xlApp.activecell.offset(0,0).VALUE > con.LastName = xlApp.activecell.offset(0,1).VALUE > con.CompanyName = xlApp.activecell.offset(0,2).VALUE > con.MobileTelephoneNumber = xlApp.activecell.offset(0,3).VALUE > con.CLOSE (0) > ENDIF > xlApp.activecell.offset(1,0).SELECT > ENDDO > wkb.CLOSE > xlApp.QUIT > xlApp = NULL >&& myOlApp.Quit > myOlApp = NULL >ENDFUNC > >PROCEDURE exit_program > MESSAGEBOX("Make sure Contacts has folder named 'text weather'",16,"Program Error") > myOlApp = NULL > > CLEAR READ ALL && Doesn't clear foundation read. > > CLOSE DATABASES > CLEAR MEMORY > CLEAR PROGRAM >* CLEAR ALL && Closes all data bases & releases memory. > CLEAR && Clean up screen. > > CANCEL && Clear foundation read. > >ENDPROC