Broken Folder Loop - Outlook 2007 (.oft files)

Status
Not open for further replies.

walu22

Member
Outlook version
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
 
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.
 
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
Retired Geek Outlook for the MAC with Yahoo accounts now very broken Using Outlook 9
P Comcast IMAP broken but their second level support said to call "the Outlook company" Using Outlook 4
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
macdotcom Outlook 365 Outlook folder export to PST archival tool - close, but need a nudge Outlook VBA and Custom Forms 2
B How to get PST folder datetime? Outlook VBA and Custom Forms 1
M Search message, then (1) Jump to folder & (2) Select message that you searched for Outlook VBA and Custom Forms 7
G Search Folders and Jump to Folder Outlook VBA and Custom Forms 2
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
P Can't add custom field to custom Outlook form, it always adds to the Folder instead Outlook VBA and Custom Forms 2
P Yahoo/IMAP folder rename by Outlook desktop 365 Using Outlook 0
A Outlook 2019 folder counter Using Outlook 0
A Search folder and move the email Outlook VBA and Custom Forms 0
N Reply to Outlook messages by moving messages to a specific Outlook folder Outlook VBA and Custom Forms 1
T How to find or display the sub-folder name for an Archive Search Using Outlook 10
A Outlook 365 (OutLook For Mac)Move "On My Computer" Folder Items From Old To New Mac Computer Using Outlook 3
P Search folder: all emails sent to or from a domain Using Outlook 1
V Folder Properties - Gmail account can't switch Using Outlook 5
Victor_50 Outlook 2019 Jump to folder from search folder Outlook VBA and Custom Forms 0
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
Kika Melo Outlook Calendar deleted appointments not in Deleted Items folder Using Outlook 3
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Adding a contact to a specific folder Using Outlook 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
Rupert Dragwater Duplicate email in Folder Using Outlook 7
S Adding a recipient's column to Sent folder in Outlook 2010 Outlook VBA and Custom Forms 1
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
CWM330 Outlook 365 Hey Diane! MS 365 Biz Standard and "Potential Spam" addressed to others coming to my JUNK folder? Using Outlook 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
A manual rule sends mail to wrong folder Using Outlook 5
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
D This folder up to date vs all folders up to date Using Outlook 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 3
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 4
S Need code to allow defined starting folder and selection from there to drill down Outlook VBA and Custom Forms 10
P Emails assigned with a certain category (within a shared inbox) to be copied to a specific folder. Outlook VBA and Custom Forms 2
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
S Folder Pane Colour Categories Using Outlook 6

Similar threads

Back
Top