Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2017, 06:47 AM
gmayor's Avatar
gmayor gmayor is offline Seeking rule/code to send emails which have been moved by rules to be autoforwarded Windows 10 Seeking rule/code to send emails which have been moved by rules to be autoforwarded Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default


Each folder needs its own unique variable name. You can only apply the variable 'Newsletters' to one of the folders - 'Newsletters' was the example used in the quoted link - more meaningful unique variable names would be required (e.g. the folder names with the spaces replaced by underscore characters).

Note that there were two folders in the quoted link, each with its own variable name and associated macro. You have more than 50 folders here?

If you set the same variable name to multiple folders, only the last folder to be set i.e. folder "NSAR" is the folder associated with that variable name.

You need to create an event for each of the 50+ folders.

Take another look at the link you quoted.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 02-19-2017, 10:31 AM
Hoxton118 Hoxton118 is offline Seeking rule/code to send emails which have been moved by rules to be autoforwarded Windows 7 32bit Seeking rule/code to send emails which have been moved by rules to be autoforwarded Office 2010 32bit
Novice
Seeking rule/code to send emails which have been moved by rules to be autoforwarded
 
Join Date: Mar 2014
Posts: 21
Hoxton118 is on a distinguished road
Default Once more....

Graham, thanks for persisting. I've interpreted what you have advised in the following code, placed in "ThisOutlookSession", but it's returning a compile error message "Invalid Attribute in Sub or Function" at the line indicated below. Grateful for any further assistance.

Code:
Option Explicit

Sub MoveFolders()

Private WithEvents NewsLetters9 As outlook.Items <<<<<<<DEBUGGER FINDS COMPILE ERROR HERE
Private WithEvents NewsLetters10 As outlook.Items
Private WithEvents NewsLetters11 As outlook.Items
Private WithEvents NewsLetters12 As outlook.Items
Private WithEvents NewsLetters13 As outlook.Items
Private WithEvents NewsLetters14 As outlook.Items
Private WithEvents NewsLetters15 As outlook.Items
Private WithEvents NewsLetters16 As outlook.Items
Private WithEvents NewsLetters17 As outlook.Items
Private WithEvents NewsLetters18 As outlook.Items
Private WithEvents NewsLetters19 As outlook.Items
Private WithEvents NewsLetters20 As outlook.Items
Private WithEvents NewsLetters21 As outlook.Items
Private WithEvents NewsLetters22 As outlook.Items
Private WithEvents NewsLetters23 As outlook.Items
Private WithEvents NewsLetters24 As outlook.Items
Private WithEvents NewsLetters25 As outlook.Items
Private WithEvents NewsLetters26 As outlook.Items
Private WithEvents NewsLetters27 As outlook.Items
Private WithEvents NewsLetters28 As outlook.Items
Private WithEvents NewsLetters29 As outlook.Items
Private WithEvents NewsLetters30 As outlook.Items
Private WithEvents NewsLetters31 As outlook.Items
Private WithEvents NewsLetters32 As outlook.Items
Private WithEvents NewsLetters33 As outlook.Items
Private WithEvents NewsLetters34 As outlook.Items
Private WithEvents NewsLetters35 As outlook.Items
Private WithEvents NewsLetters36 As outlook.Items
Private WithEvents NewsLetters37 As outlook.Items
Private WithEvents NewsLetters38 As outlook.Items
Private WithEvents NewsLetters39 As outlook.Items
Private WithEvents NewsLetters40 As outlook.Items
Private WithEvents NewsLetters42 As outlook.Items
Private WithEvents NewsLetters43 As outlook.Items
Private WithEvents NewsLetters44 As outlook.Items
Private WithEvents NewsLetters45 As outlook.Items
Private WithEvents NewsLetters46 As outlook.Items
Private WithEvents NewsLetters47 As outlook.Items
Private WithEvents NewsLetters48 As outlook.Items
Private WithEvents NewsLetters49 As outlook.Items
Private WithEvents NewsLetters50 As outlook.Items
Private WithEvents NewsLetters51 As outlook.Items
Private WithEvents NewsLetters52 As outlook.Items
Private WithEvents NewsLetters53 As outlook.Items
Private WithEvents NewsLetters54 As outlook.Items
Private WithEvents NewsLetters55 As outlook.Items
Private WithEvents NewsLetters56 As outlook.Items
Private WithEvents NewsLetters57 As outlook.Items
Private WithEvents NewsLetters58 As outlook.Items
Private WithEvents NewsLetters59 As outlook.Items
Private WithEvents NewsLetters60 As outlook.Items
Private WithEvents NewsLetters61 As outlook.Items
Private WithEvents NewsLetters62 As outlook.Items
Private WithEvents NewsLetters63 As outlook.Items
Private WithEvents NewsLetters64 As outlook.Items
Private WithEvents NewsLetters65 As outlook.Items
Private WithEvents NewsLetters66 As outlook.Items
Private WithEvents NewsLetters67 As outlook.Items
Private WithEvents NewsLetters68 As outlook.Items
Private WithEvents NewsLetters69 As outlook.Items
Private WithEvents NewsLetters70 As outlook.Items
Private WithEvents NewsLetters71 As outlook.Items
Private WithEvents NewsLetters72 As outlook.Items
Private WithEvents NewsLetters73 As outlook.Items
Private WithEvents NewsLetters74 As outlook.Items
Private WithEvents NewsLetters75 As outlook.Items

Private olItem As outlook.MailItem

Private Sub Application_Startup()
Dim olApp As outlook.Application
    Set olApp = outlook.Application

SetNewsLetters9 = GetNS(olApp).GetDefaultFolder(WSJEveningWrap).Items
SetNewsLetters10 = GetNS(olApp).GetDefaultFolder(WSJTechnologyUpdate).Items
SetNewsLetters11 = GetNS(olApp).GetDefaultFolder(WSJRealTimeEconomics).Items
SetNewsLetters12 = GetNS(olApp).GetDefaultFolder(WSJOpinion).Items
SetNewsLetters13 = GetNS(olApp).GetDefaultFolder(WSJLifeAndArts).Items
SetNewsLetters14 = GetNS(olApp).GetDefaultFolder(myFT).Items
SetNewsLetters15 = GetNS(olApp).GetDefaultFolder(WSJ10point).Items
SetNewsLetters16 = GetNS(olApp).GetDefaultFolder(FTUKPolitics).Items
SetNewsLetters17 = GetNS(olApp).GetDefaultFolder(FTFreeLunch).Items
SetNewsLetters18 = GetNS(olApp).GetDefaultFolder(FTBrussels).Items
SetNewsLetters19 = GetNS(olApp).GetDefaultFolder(FTBrexit).Items
SetNewsLetters20 = GetNS(olApp).GetDefaultFolder(FirstFT).Items
SetNewsLetters21 = GetNS(olApp).GetDefaultFolder(LexEurope).Items
SetNewsLetters22 = GetNS(olApp).GetDefaultFolder(CNBreakingNews).Items
SetNewsLetters23 = GetNS(olApp).GetDefaultFolder(CNDailyNews).Items
SetNewsLetters24 = GetNS(olApp).GetDefaultFolder(CNBriefing).Items
SetNewsLetters25 = GetNS(olApp).GetDefaultFolder(FTEnergy).Items
SetNewsLetters26 = GetNS(olApp).GetDefaultFolder(FTEditorsChoice).Items
SetNewsLetters27 = GetNS(olApp).GetDefaultFolder(WSJEnergy).Items
SetNewsLetters28 = GetNS(olApp).GetDefaultFolder(WSJCMOToday).Items
SetNewsLetters29 = GetNS(olApp).GetDefaultFolder(Lex).Items
SetNewsLetters30 = GetNS(olApp).GetDefaultFolder(techFT).Items
SetNewsLetters31 = GetNS(olApp).GetDefaultFolder(FTWhiteHouse).Items
SetNewsLetters32 = GetNS(olApp).GetDefaultFolder(WSJTodaysPaperEurope).Items
SetNewsLetters33 = GetNS(olApp).GetDefaultFolder(WSJTechnologyAlert).Items
SetNewsLetters34 = GetNS(olApp).GetDefaultFolder(WSJPoliticsAlert).Items
SetNewsLetters35 = GetNS(olApp).GetDefaultFolder(WSJNewsAlert).Items
SetNewsLetters36 = GetNS(olApp).GetDefaultFolder(WSJEuropeAlert).Items
SetNewsLetters37 = GetNS(olApp).GetDefaultFolder(WSJBrexit).Items
SetNewsLetters38 = GetNS(olApp).GetDefaultFolder(WSJCity).Items
SetNewsLetters39 = GetNS(olApp).GetDefaultFolder(IfG).Items
SetNewsLetters40 = GetNS(olApp).GetDefaultFolder(Upshot).Items
SetNewsLetters42 = GetNS(olApp).GetDefaultFolder(WSJCIOJournal).Items
SetNewsLetters43 = GetNS(olApp).GetDefaultFolder(WSJPersonalTechnology).Items
SetNewsLetters44 = GetNS(olApp).GetDefaultFolder(InfrastructureIntelligence).Items
SetNewsLetters45 = GetNS(olApp).GetDefaultFolder(FTWeekend).Items
SetNewsLetters46 = GetNS(olApp).GetDefaultFolder(FTNewsmine).Items
SetNewsLetters47 = GetNS(olApp).GetDefaultFolder(CICBrexit).Items
SetNewsLetters48 = GetNS(olApp).GetDefaultFolder(FTother).Items
SetNewsLetters49 = GetNS(olApp).GetDefaultFolder(CommunicationsDirector).Items
SetNewsLetters50 = GetNS(olApp).GetDefaultFolder(WSJBestofWeb).Items
SetNewsLetters51 = GetNS(olApp).GetDefaultFolder(Economist).Items
SetNewsLetters52 = GetNS(olApp).GetDefaultFolder(HBR).Items
SetNewsLetters53 = GetNS(olApp).GetDefaultFolder(MRC).Items
SetNewsLetters54 = GetNS(olApp).GetDefaultFolder(NAO).Items
SetNewsLetters55 = GetNS(olApp).GetDefaultFolder(ONS).Items
SetNewsLetters56 = GetNS(olApp).GetDefaultFolder(UKParliament).Items
SetNewsLetters57 = GetNS(olApp).GetDefaultFolder(OpenUniversity).Items
SetNewsLetters58 = GetNS(olApp).GetDefaultFolder(UKDefenceJournal).Items
SetNewsLetters59 = GetNS(olApp).GetDefaultFolder(ESRC).Items
SetNewsLetters60 = GetNS(olApp).GetDefaultFolder(NDA).Items
SetNewsLetters61 = GetNS(olApp).GetDefaultFolder(BEIS).Items
SetNewsLetters62 = GetNS(olApp).GetDefaultFolder(Wonkhe).Items
SetNewsLetters63 = GetNS(olApp).GetDefaultFolder(MITSloan).Items
SetNewsLetters64 = GetNS(olApp).GetDefaultFolder(Building).Items
SetNewsLetters65 = GetNS(olApp).GetDefaultFolder(DepartmentofHealth).Items
SetNewsLetters66 = GetNS(olApp).GetDefaultFolder(Raconteur).Items
SetNewsLetters67 = GetNS(olApp).GetDefaultFolder(CIC).Items
SetNewsLetters68 = GetNS(olApp).GetDefaultFolder(NYT).Items
SetNewsLetters69 = GetNS(olApp).GetDefaultFolder(PoliticsHome).Items
SetNewsLetters70 = GetNS(olApp).GetDefaultFolder(CNother).Items
SetNewsLetters71 = GetNS(olApp).GetDefaultFolder(UniversitiesUK).Items
SetNewsLetters72 = GetNS(olApp).GetDefaultFolder(InnovateUK).Items
SetNewsLetters73 = GetNS(olApp).GetDefaultFolder(DesignCouncil).Items
SetNewsLetters74 = GetNS(olApp).GetDefaultFolder(UKinaChangingEurope).Items
SetNewsLetters75 = GetNS(olApp).GetDefaultFolder(NSAR).Items

lbl_Exit:
    Exit Sub
End Sub

Private Sub Newsletters_ItemAdd(ByVal item As Object)
    On Error GoTo err_Handler
    Set olItem = item.Forward
    With olItem
        .To = "external.affairs@apm.org.uk"
        .Send
    End With
lbl_Exit:
    Exit Sub
err_Handler:
    MsgBox Err.Number & " - " & Err.Description
    GoTo lbl_Exit

End Sub


Function GetNS(ByRef app As outlook.Application) As outlook.NameSpace
    Set GetNS = app.GetNamespace("MAPI")
lbl_Exit:
    Exit Function
End Function

Last edited by Hoxton118; 02-19-2017 at 10:32 AM. Reason: forgot code brackets
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeking rule/code to send emails which have been moved by rules to be autoforwarded Outlook rule to not send if attachment name doesn't match criteria SerenityNetworks Outlook 10 03-20-2016 10:56 AM
Seeking rule/code to send emails which have been moved by rules to be autoforwarded Want to set up a rule to move sent emails mylan Outlook 2 07-08-2014 05:10 AM
Rule to remove duplicate emails? ReviTULize Outlook 0 05-14-2013 01:15 PM
Rule doesn't work on BCC emails LeakyMemory Outlook 0 04-21-2012 04:07 AM
Rule=Delayed send markg2 Outlook 0 08-01-2010 07:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:51 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft