Create new item in public folder using VBscript

Status
Not open for further replies.

Trygve

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Hi everyone. I'm trying to create a new task item based on a custom form, which will be executed by a button in that form. The custom form folder is in a public folder.

For now I have the following code in my custom form:
Code:
Sub cmdKorrFart_Click()
    Dim myFolder, myTask
    Set myFolder = Application.ActiveExplorer.CurrentFolder
    Set myTask = myFolder.Items.Add
    myTask.Display
End Sub

That works as long as I'm in that public folder. But if I go into the inbox to - for example - copy something from a mail into the form, then the inbox suddenly becomes the current folder, so then the code creates a mail item instead of a task item based on the form, unless I actively go back into the public folder by selecting it.

So my question is: How can I make Outlook create a new task item without using the CurrentFolder method? The public folder is in this location: All Public Folders\Sites\Romeo\Production\BIS\Booking\BookingForm.

I'm guessing it involves using GetDefaultFolder, but I'm not sure how to put it all together.

Thanks!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to reference the folder path and walk down. It's not recommended to use too many dots in the path, so you'll need to work your way down if its nested
Set myPF = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("sites")
set myPFtree = mypf.folders("romeo").folders("production")
set mytaskfolder = myPFtree("bis").folders("booking").folders("bookingform")
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Outlook 2010 trying to create calendar/task entries generates error "Could not save item.The connect Using Outlook 2
A Outlook 2010 trying to create calendar/task entries generates error "Could not save item.The connect Using Outlook 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
L create new mail item from current item Outlook VBA and Custom Forms 4
Chiba Create an appointment for all the members Outlook VBA and Custom Forms 1
S Create a clickable custom column field Outlook VBA and Custom Forms 0
O Create a custom contact form - questions before messing things up... Outlook VBA and Custom Forms 4
C Can't create Outlook data file Outlook Wishlist 0
L automaticaly create a teams meeting with a sync Using Outlook 0
D Can Exchange Admin Center create a pst for users email/contacts/calendar? Exchange Server Administration 0
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
F How to create phone number as links in notes of Contacts Using Outlook 2
Nessa Can't create new appointment Using Outlook 1
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
C Create new Message with shared contacts & BCC'ing recipients Outlook VBA and Custom Forms 0
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
G Can't create Folder Groups in Outlook 2013 Using Outlook 0
N Outlook rules don't create a copy for bcc'ed emails Using Outlook 3
F Delete/create/reset Exchange mailbox on Outlook.com Using Outlook.com accounts in Outlook 3
R Can not create folder to store specific emails in in Outlook for Mac Using Outlook 1
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
JackBlack What tools do you use to create the signature for email? Using Outlook 3
Rupert Dragwater How to create a new email with @outlook.com Using Outlook.com accounts in Outlook 32
F Should a new email account also create new contacts Using Outlook 2
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
R Outlook add-in to create new contact from an email. Using Outlook 0
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
Q Script to create a pst file for Archiving Using Outlook 1
Jennifer Murphy Can I create a Rule with Or'd conditions? Using Outlook 1
D Outlook macros to create meeting on shared calendar Outlook VBA and Custom Forms 10
G How do I create a custom pick list in VB for an outlook automated email? Outlook VBA and Custom Forms 1
L Create Custom Form Using Outlook 0
Diane Poremsky Create a Task when a Message is Flagged New Slipstick.com Articles 0
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
Diane Poremsky Create a custom field for Outlook messages New Slipstick.com Articles 0
Mark White vba to create a shared mailbox folder Outlook VBA and Custom Forms 3
Diane Poremsky Automatically create a task when sending a message New Slipstick.com Articles 0
Diane Poremsky Create a Custom Numbering Field for Outlook messages New Slipstick.com Articles 0
Diane Poremsky Create a Series of Tasks using VBA New Slipstick.com Articles 0
J create .pst data file for new gmail account Using Outlook.com accounts in Outlook 1
Diane Poremsky Create an Organizational Forms Library New Slipstick.com Articles 0
Diane Poremsky Create an Organizational Forms Library in Exchange 2013 or Office 365 New Slipstick.com Articles 0
Jeanne Goodman Create Printout from Multiple Shared Calendars Outlook VBA and Custom Forms 8
Diane Poremsky Manually create a POP3 account in Outlook 2007 New Slipstick.com Articles 0
T Create Rule For Secondary E-Mail Address In Outlook 2016 Using Outlook 4
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
Diane Poremsky Create Appointments Using Spreadsheet Data New Slipstick.com Articles 0
A VBA to create meeting from template from a time slot selected in someone's calendar Outlook VBA and Custom Forms 5

Similar threads

Top