the folder condition is necessary in Outloook VBS

Status
Not open for further replies.

Simpler45

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
help to solve a problem:
the condition if there is no folder ("Globality") it is necessary is created if there is a folder ("Globality") it is removed and again is created

Dim objXls
Dim i, j
Dim myNameSpace
Dim myFolder, myWorkFolder
Dim myOutlook
Dim myItems
Dim myNewFolder
Set objXls = CreateObject("Excel.Application")
objXls.Workbooks.Open "C:\Data.xls"
'укажите путь и имя существующего файла
objXls.Application.Visible = False
Set myOutlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(10)
Set myNewFolder = myFolder.Folders.Add("Globality")
j = objXls.ActiveSheet.UsedRange.Rows.Count
For i = 1 To j
Set myItems = myNewFolder.Items.Add("IPM.Contact")
With myItems
.FullName = objXls.ActiveSheet.Range("A" & i).Value & " " & _
objXls.ActiveSheet.Range("B" & i).Value & " " & _
objXls.ActiveSheet.Range("C" & i).Value
.Birthday = objXls.ActiveSheet.Range("D" & i).Value
.Email1Address = objXls.ActiveSheet.Range("E" & i).Value
.Save
End With
Next
objXls.quit
Set objXls = Nothing
Set myOutlook = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myNewFolder = Nothing
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
instead of
Set myNewFolder = myFolder.Folders.Add("Globality")

Try this - use on error resume next to keep the macro moving and set the folder. If it errors, create the folder. if you want it deleted and added again, you'll use the same method - attempt to delete it (myNewFolder.Delete) and if it errors, keep moving and create it. (or, check for and delete the contents of the folder after you check to see if it exists.)

On Error Resume Next
Set myNewFolder = myFolder.Folders("Globality")
If myNewFolder Is Nothing Then
Set myNewFolder = myFolder.Folders.Add("Globality")
End If
 

Simpler45

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
thank you very much all turned
help still it is necessary that each time at script start, the folder ("Globality") was cleared of contacts, and contacts from document.xls were added then
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you can either use myNewFolder.delete right after you first set it then instead of checking for it 'if mynewfolder is nothing' , jump right to Adding it.

or loop through the folder and delete the contents - something like this
Set myNewFolder = myFolder.Folders("Globality")
for i = myNewFolder.Items.Count to 1 step -1
myNewFolder.Items(i).Delete
next
 

Simpler45

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
help there was one more question.
at creation of the folder ("Birthday") to add in the folder description - date of change of the Birthday.xls file, At the subsequent script performance if date of the description of the folder ("Birthday") in Outlook and date of change of the Birthday.xls file - different, is created the new folder with the description of date of change of the new Birthday.xls file if they identical that anything doesn't occur.

Dim objXls
Dim i, j
Dim myNameSpace
Dim myFolder, myWorkFolder
Dim myOutlook
Dim myItems
Dim myNewFolder
Set objXls = CreateObject("Excel.Application")
objXls.Workbooks.Open "\\SRVDC0802\Install\birthday.xls"
'укажите путь и имя существующего файла
objXls.Application.Visible = False
Set myOutlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(10)
On Error Resume Next
Set myNewFolder = myFolder.Folders("Birthday")
If myNewFolder Is Nothing Then
Set myNewFolder = myFolder.Folders.Add("Birthday")
End If
Set myNewFolder = myFolder.Folders("Birthday")
for i = myNewFolder.Items.Count to 1 step -1
myNewFolder.Items(i).Delete
next
j = objXls.ActiveSheet.UsedRange.Rows.Count
For i = 1 To j
Set myItems = myNewFolder.Items.Add("IPM.Contact")
With myItems
.FullName = objXls.ActiveSheet.Range("A" & i).Value & " " & _
objXls.ActiveSheet.Range("B" & i).Value & " " & _
objXls.ActiveSheet.Range("C" & i).Value
.Birthday = objXls.ActiveSheet.Range("D" & i).Value
.Email1Address = objXls.ActiveSheet.Range("E" & i).Value
.Save
End With
Next
objXls.quit
Set objXls = Nothing
Set myOutlook = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myNewFolder = Nothing
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The folder description field should be .Description

Set myNewFolder = myFolder.Folders.Add("Birthday")
myNewFolder.Description = "The Description"
 

Simpler45

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Create file found property, as now you can link with "The Description"

Function ShowFileInfo(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
ShowFileInfo = "Created: " & f.DateCreated
End Function
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Oh, yeah, you need to use the FSO - I missed the part where you wanted to use the date of the XLS sheet as the description.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
O Cannot expand the folder. The set of folders cannot be opened. You do not have permission to log on. Using Outlook 1
F Jump to Inbox folder when click on Favorite Using Outlook 8
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 5
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
P Posts in Folder No Longer Group by Conversation Column After Search Using Outlook 0
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
Horsepower Moving emails between folder Outlook for Mac Outlook Wishlist 8
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
D How to remove a folder, option grayed out Using Outlook 4
D How To Combine Share Task Folders in just one Folder Using Outlook 0
G Retention Policy for Outlook.com Deleted Items folder Using Outlook 0
Z Outlook 365 delete reminder you can’t make change to contents of this-read only folder Using Outlook 4
O The Outlook API wrongfully shows an outlook folder to have zero sub-folders Outlook VBA and Custom Forms 1
O The Outlook API wrongfully shows an outlook folder to have zero sub-folders Outlook VBA and Custom Forms 2
S Outlook (2016 32bit; Gmail IMAP) - Save sent message to Outllook Folder Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
G How to add a folder shortcut to outlook quick access toolbar? Using Outlook 6
G Add to Outlook Contacts - Point to non-default contacts folder Using Outlook 0
M Move to Folder Using Outlook 1
K Export Folder to PST Outlook VBA and Custom Forms 2
B Spam folder not showing in Outlook Using Outlook 5
D Is a sub folder under contacts necessary to be able to name an Address Book? Using Outlook 1
J Moved many emails to Outlook external folder, need to delete on Gmail server Using Outlook 14
A Going to folder using shortcuts Using Outlook 3
B Outlook 2016 Auto-archive creates new folder Using Outlook 3
B BCC issues after changing root folder path for gmail Using Outlook 1
Fozzie Bear Outlook 2016 Creating a shared local Contacts folder Using Outlook 2
A Cannot copy this folder because it may contain private items Using Outlook 0
A Unable to save recurring Meeting to Documents folder due to error Using Outlook 2
B Extracting email addresses from a folder - how to also get the name of the person the address is for? Using Outlook 5
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1
J Moving Imported folder Using Outlook 2
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
J Sent Items Folder NOT Showing Correct From Email Address Using Outlook 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
Retired Geek Junk Folder Clean Up Rules Exchange Server Administration 1
D Outlook 2016 Deleting emails without affecting folder structure - Outlook Office 365 Using Outlook 3
B Outlook 365 - Folder pane list clears Using Outlook 28
P Add, remove, & reorder folder pane Using Outlook 6
R Folder pane width change Using Outlook 76
T Missing Folder in Outlook.com Using Outlook 3
R Setup autofoward rule on a particular folder in Outlook Using Outlook 0
T After I send a new email, it remains in the Draft folder Using Outlook.com accounts in Outlook 3
N Outlook 2016 Folder Icons Look Using Outlook 0
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0

Similar threads

Top