Broken Folder Loop - Outlook 2007 (.oft files)

Status
Not open for further replies.

walu22

Member
Outlook version
Outlook 2007
Email Account
Hello,

I cobbled together the following code (which is designed to loop through a template folder, open each file, and save it as a draft) from examples online. It's presented below.

Code:
Public Sub CreateFromTemplateLoop()
   Dim MyItem As Outlook.MailItem
   Dim myOlApp As Outlook.Application
   Dim MyFolder As String
   Dim MyFile As String
   MyFolder = "C:\Users\walu22\Documents\I'm Going Nuts Here!"
   MyFile = Dir(MyFolder & "\*.oft")
   Do While MyFile <> ""
   Set myOlApp = CreateObject("Outlook.Application")
   Set MyItem = myOlApp.CreateItemFromTemplate(MyFile, _
           myOlApp.Session.GetDefaultFolder(olFolderDrafts))
   MyItem.Display
   MyItem.Save
   MyItem.Close olPromptForSave
   MyFile = Dir
   Loop 
 
End Sub

It worked perfectly the first time I used it, but ever since I restarted my outlook, it's been yelling at me. Here's the error message it returns:

http://farm8.staticflickr.com/7316/10614702404_c993e9e2d8.jpg

2147287038 (80030002)

Cannot open file. The file may not exist, you may not have permission to open it, or it may be open in another program.

I have no clue what the problem as all the files open fine when doing a single macro. For example, this works okay.

Code:
Public Sub SIMIncomeGrowth() 
 
Set msg = Application.CreateItemFromTemplate("C:\Users\walu22\Documents\I'm Going Nuts Here!\Income1.oft") 
 
msg.Display 
 
End Sub

Any guidance would be appreciated.

Cheers,

walu22
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Hmmm. It get that error immediately.

Ok - to test it, i added debug.print to see what myfile is -
MyFile = Dir(MyFolder & "*.oft")
Debug.Print MyFile
Do While MyFile <> ""



only the file name, not the entire path was printed. When i used the folder path in create from template, it worked:

CreateItemFromTemplate(MyFolder & MyFile,

So... on the restart outlook doesn't know where to look - you need to pass the full path it to.
 

walu22

Member
Outlook version
Outlook 2007
Email Account
Hmmm. It get that error immediately.

Ok - to test it, i added debug.print to see what myfile is -

MyFile = Dir(MyFolder & "*.oft")

Debug.Print MyFile

Do While MyFile <> ""

only the file name, not the entire path was printed. When i used the folder path in create from template, it worked:

CreateItemFromTemplate(MyFolder & MyFile,

So... on the restart outlook doesn't know where to look - you need to pass the full path it to.

Worked like a charm! Thank you much, Diane. :D

Here's the code for those interested:

Code:
Public Sub CreateFromTemplateLoop()
   Dim MyItem As Outlook.MailItem
   Dim myOlApp As Outlook.Application
   Dim MyFolder As String
   Dim MyFile As String
   MyFolder = "C:\Users\walu22\AppData\Roaming\Microsoft\Templates\Individual Statements\"
   MyFile = Dir(MyFolder & "\*.oft")
   Do While MyFile <> ""
   Set myOlApp = CreateObject("Outlook.Application")
   Set MyItem = myOlApp.CreateItemFromTemplate(MyFolder & MyFile, _
           myOlApp.Session.GetDefaultFolder(olFolderDrafts))
   MyItem.Display
   MyItem.Save
   MyItem.Close olPromptForSave
   MyFile = Dir
   Loop 
 
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P auto-complete is hopelessly broken Using Outlook 0
David Langer Store my Outlook settings in the cloud - Broken Using Outlook 4
R outlook address book search broken Using Outlook 2
R Outlook 2013 - IMAP & Rules Broken Using Outlook 1
P Outlook 2013 search broken after upgrade from 2010 Using Outlook 0
T I've broken my installation (OL 2013) Using Outlook 0
M HTML mails apprearing broken in outlook 2013 Using Outlook 5
M Fixing broken Journal links to Contacts in Outlook 2007 Outlook VBA and Custom Forms 3
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

Similar threads

Top