|
|
Subject:
Need VBA code help - Outlook View Object
Category: Computers > Software Asked by: sherpaj-ga List Price: $40.00 |
Posted:
08 Apr 2005 16:56 PDT
Expires: 08 May 2005 16:56 PDT Question ID: 506975 |
I am trying to lock my views in Outlook, so that a change in my views is not retained when I accidentally click on the column headers in one of my Outlook folders. I have done a lot of research on this and have found the code below. I have put it in VBA, but it does not work and need someone to help me troubleshoot it. 1. Is the code below what I need? I'm not a programmer, so I'm not really sure. 2. Why is it not working? I don't get any error messages, so maybe I'm just doing something wrong. I have pasted the code into a VBA module, saved, set my Macro settings to low and restarted Outlook. I got this code from the following website: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol11/html/olproLockUserChanges_HV03081803.asp Sub LocksPublicViews() 'Locks the interface of all views that are available to 'all users of this folder. Dim olApp As Outlook.Application Dim objName As Outlook.NameSpace Dim objViews As Outlook.Views Dim objView As Outlook.View Set olApp = New Outlook.Application Set objName = olApp.GetNamespace("MAPI") Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView End Sub Sub LockView(ByRef objView As View, ByVal blnAns As Boolean) 'Locks the user interface of the view. 'Accepts and returns a View object and user response. With objView If blnAns = True Then 'if true lock UI .LockUserChanges = True .Save Else 'if false don't lock UI .LockUserChanges = False End If End With End Sub |
|
There is no answer at this time. |
|
Subject:
Re: Need VBA code help - Outlook View Object
From: pmmbala1976-ga on 13 Apr 2005 07:28 PDT |
Hi, Set objViews = objName.GetDefaultFolder(olFolderNotes).Views In this line you used olFolderNotes. instead of that try use olFolderInbox or olPublicFoldersAllPublicFolders. so it should be like this Set objViews = objName.GetDefaultFolder(olFolderInbox).Views List : olFolderCalendar olFolderContacts olFolderDeletedItems olFolderDrafts olFolderInbox olFolderJournal olFolderNotes olFolderOutbox olFolderSentMail olFolderTasks olPublicFoldersAllPublicFolders Thanks Bala |
Subject:
Re: Need VBA code help - Outlook View Object
From: sherpaj-ga on 14 Apr 2005 14:35 PDT |
Awesome! Is there a way to apply this to all folders within this script or do I need to copy and paste the entire entry and set it for each folder separately? If you want to repost your comment as an answer, I can accept it and close the question.... |
Subject:
Re: Need VBA code help - Outlook View Object
From: pmmbala1976-ga on 14 Apr 2005 21:06 PDT |
Hi, Try the first way, if doesnt work, you need to copy the second way. First way: Sub LocksPublicViews() 'Locks the interface of all views that are available to 'all users of this folder. Dim olApp As Outlook.Application Dim objName As Outlook.NameSpace Dim objViews As Outlook.Views Dim objView As Outlook.View Set olApp = New Outlook.Application Set objName = olApp.GetNamespace("MAPI") Set objViews = objName.GetDefaultFolder(olPublicFoldersAllPublicFolders).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView).Views End Sub Second way: Sub LocksPublicViews() 'Locks the interface of all views that are available to 'all users of this folder. Dim olApp As Outlook.Application Dim objName As Outlook.NameSpace Dim objViews As Outlook.Views Dim objView As Outlook.View Set olApp = New Outlook.Application Set objName = olApp.GetNamespace("MAPI") Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderCalendar).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderContacts).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderDeletedItems).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderDrafts).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderInbox).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderJournal).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderOutbox).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderSentMail).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderTasks).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olPublicFoldersAllPublicFolders).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView).Views end sub Thanks Bala |
Subject:
Re: Need VBA code help - Outlook View Object
From: sherpaj-ga on 19 Apr 2005 12:41 PDT |
pmmbala, I've tried it, but I get an error when I try the macro. Something like sub/function not defined. It highlights the first line of code yellow, but I don't know what to do with it. Any idea you may have would be much appreciated. |
Subject:
Re: Need VBA code help - Outlook View Object
From: pmmbala1976-ga on 19 Apr 2005 22:00 PDT |
Ok.. try to copy the below code and try. Sub LocksPublicViews() 'Locks the interface of all views that are available to 'all users of this folder. Dim olApp As Outlook.Application Dim objName As Outlook.NameSpace Dim objViews As Outlook.Views Dim objView As Outlook.View Set olApp = New Outlook.Application Set objName = olApp.GetNamespace("MAPI") Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderCalendar).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderContacts).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderDeletedItems).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderDrafts).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderInbox).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderJournal).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderOutbox).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderSentMail).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderTasks).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then Call LockView(objView, True) End If Next objView End Sub Sub LockView(ByRef objView As View, ByVal blnAns As Boolean) 'Locks the user interface of the view. 'Accepts and returns a View object and user response. With objView If blnAns = True Then 'if true lock UI .LockUserChanges = True .Save Else 'if false don't lock UI .LockUserChanges = False End If End With End Sub Thanks Bala |
Subject:
Re: Need VBA code help - Outlook View Object
From: sherpaj-ga on 22 Apr 2005 16:47 PDT |
Hi Bala, I tried this code and do not get an error message any more. However, it only seems to work in mail folders. I also tried changing the command in the original code that I had according to your instructions, but I am getting the same result. Do you have any idea why this may be occuring? Thanks, Sabrina |
Subject:
Re: Need VBA code help - Outlook View Object
From: pmmbala1976-ga on 22 Apr 2005 18:39 PDT |
Hi Sabrina, Can you please explain me more details about your problem. i mean what do you expect the code to do? Please.. Thanks Balakumar |
Subject:
Re: Need VBA code help - Outlook View Object
From: sherpaj-ga on 23 Apr 2005 12:22 PDT |
Hi Bala, I have a lot of custom views that I created in several folders in Outlook. For example, I sort by different criteria in the tasks folder (i.e. first by due date, then by priority, then by subject) and also organize them by category. I sometimes find myself accidentally clicking on the column header bar and that blows away all of these settings. For example, I accidentally click on the subject header - now all of my tasks are sorted by subject only and the categories are gone. I have to manually set them back to sort and categorize in the way that I had originally set them to. Having tried this code with your advice in the inbox (where I only use the Outlook standard view), I have tried to click on the column header that sorts email by date, setting the oldest email to sort from the top. When I get off the inbox and then go back to it, it is set back to sort the newest email on top. The way it was set originally. I have also tried to use the code on other Outlook folders, where I use Outlook views, thinking it might have to do with my custom views. However, it didn't work in other Outlook folders on Outlook views. I would like the functionality described above for all of my Outlook folders, but somehow it is only working in the inbox. Another option is not to be able to click on the column headers at all. I usually go into Customize Current View to modify a view. But I haven't found anything to disable the ability to click on the column headers. |
Subject:
Re: Need VBA code help - Outlook View Object
From: pmmbala1976-ga on 23 Apr 2005 13:12 PDT |
Hi Instead of this keyword,"olViewSaveOptionThisFolderEveryone" try to replace the below options and try. (one by one) 1.olViewSaveOptionThisFolderOnlyMe 2.olViewSaveOptionAllFoldersOfType if this wont workout mean i'll try a different way. Thanks Bala |
Subject:
Re: Need VBA code help - Outlook View Object
From: pmmbala1976-ga on 23 Apr 2005 13:17 PDT |
So your code should be like this... Sub LocksPublicViews() 'Locks the interface of all views that are available to 'all users of this folder. Dim olApp As Outlook.Application Dim objName As Outlook.NameSpace Dim objViews As Outlook.Views Dim objView As Outlook.View Set olApp = New Outlook.Application Set objName = olApp.GetNamespace("MAPI") Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderCalendar).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderContacts).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderDeletedItems).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderDrafts).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderInbox).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderJournal).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderNotes).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderOutbox).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderSentMail).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView Set objViews = objName.GetDefaultFolder(olFolderTasks).Views For Each objView In objViews If objView.SaveOption = olViewSaveOptionAllFoldersOfType Then Call LockView(objView, True) End If Next objView End Sub Sub LockView(ByRef objView As View, ByVal blnAns As Boolean) 'Locks the user interface of the view. 'Accepts and returns a View object and user response. With objView If blnAns = True Then 'if true lock UI .LockUserChanges = True .Save Else 'if false don't lock UI .LockUserChanges = False End If End With End Sub Thanks Bala |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |