A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook 2003... search for line break char



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old October 4th 07, 03:45 PM posted to microsoft.public.outlook.program_vba
Ben Bradley
external usenet poster
 
Posts: 9
Default Outlook 2003... search for line break char

Hi Sue

This is what I've changed the code to, but it doesn't seem to work.

I was hoping it would flag each email with a yellow flag, but when I
click 'Run' it just disappears and no mails are flagged.


Sub DoSearch()
Dim fld As Outlook.MAPIFolder
Dim itm As Object
Dim strFind As String
On Error Resume Next
Set fld = Application.Session.Folders("BB WEBSITE FORMS")
strFind = "double-sized listing?" & vbCrLf & "Yes"
' or vbLf it's line feed not a complete CRLF
For Each itm In fld.Items
If InStr(1, Item.Body, strFind, vbTextCompare) 0 Then
itm.FlagIcon = olYellowFlagIcon
itm.Save
End If
Next
Set itm = Nothing
Set fld = Nothing
End Sub



Do I need to specify that it's actually a sub-folder within my Inbox?
Or does the macro just look at the folder name and know where in the
Mailbox it's located?
What happens if you have many folders with the same name but in
different locations within your mailbox?


Thanks
Ben


Sue Mosher [MVP-Outlook] wrote:
Every folder has a Folders collection that represents its subfolders. Each subfolder in a Folders collection must have a unique name. Hence, you can use fld.Folders("BB Website Forms").

Ads
  #12  
Old October 4th 07, 04:48 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Outlook 2003... search for line break char

Do I need to specify that it's actually a sub-folder within my Inbox?

Absolutely, using the Folders collection of the Inbox folder, not the Namespace object.

You can't just set an icon. You must also actually flag the messages. That involves setting the FlagStatus property to olFlagMarked.

If you step through the code, is it finding the text in the body? If not, maybe the break is a vbLf, not a vbCrLf.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Ben Bradley" wrote in message ...
Hi Sue

This is what I've changed the code to, but it doesn't seem to work.

I was hoping it would flag each email with a yellow flag, but when I
click 'Run' it just disappears and no mails are flagged.


Sub DoSearch()
Dim fld As Outlook.MAPIFolder
Dim itm As Object
Dim strFind As String
On Error Resume Next
Set fld = Application.Session.Folders("BB WEBSITE FORMS")
strFind = "double-sized listing?" & vbCrLf & "Yes"
' or vbLf it's line feed not a complete CRLF
For Each itm In fld.Items
If InStr(1, Item.Body, strFind, vbTextCompare) 0 Then
itm.FlagIcon = olYellowFlagIcon
itm.Save
End If
Next
Set itm = Nothing
Set fld = Nothing
End Sub



Do I need to specify that it's actually a sub-folder within my Inbox?
Or does the macro just look at the folder name and know where in the
Mailbox it's located?
What happens if you have many folders with the same name but in
different locations within your mailbox?


Thanks
Ben


Sue Mosher [MVP-Outlook] wrote:
Every folder has a Folders collection that represents its subfolders. Each subfolder in a Folders collection must have a unique name. Hence, you can use fld.Folders("BB Website Forms").

  #13  
Old October 5th 07, 09:29 AM posted to microsoft.public.outlook.program_vba
Ben Bradley
external usenet poster
 
Posts: 9
Default Outlook 2003... search for line break char

Hi Sue

When I initially tried your version of the script, the msg box saying "I
found one!" popped up several times.

So line 8 is obviously returning true at some point.


So this is what I've modified the code to:

01 Sub DoSearch()
02 Dim fld As Outlook.MAPIFolder
03 Dim itm As Object
04 Dim strFind As String
05 On Error Resume Next
06 Set fld = Application.Session.GetDefaultFolder(olFolderInbox )
07 'Set fld = Application.Session.Folders("BUILDER BOOK TEST")
08 strFind = "double-sized listing?" & vbCrLf & "Yes"
09 ' or vbLf it's line feed not a complete CRLF
10 For Each itm In fld.Items
11 If InStr(1, Item.Body, strFind, vbTextCompare) 0 Then
12 MsgBox "You found one!"
13 itm.FlagStatus = olFlagMarked
14 itm.FlagIcon = olYellowFlagIcon
15 itm.Save
16 End If
17 Next
18 Set itm = Nothing
19 Set fld = Nothing
20 End Sub


When I run the above macro all it seems to do is flag all the messages
in my inbox to a yellow flag.

Note lines 6/7 where I'm trying to specify the folder.
Line 6 was your initial example, which seems to flag all messages in the
inbox as yellow.
Line 7 is my attempt which doesn't do anything... running the macro the
screen flickers a bit then just returns to the macro screen.

Is my line 7 syntax correct?


Thanks
Ben


Sue Mosher [MVP-Outlook] wrote:
Do I need to specify that it's actually a sub-folder within my Inbox?


Absolutely, using the Folders collection of the Inbox folder, not the Namespace object.

You can't just set an icon. You must also actually flag the messages. That involves setting the FlagStatus property to olFlagMarked.

If you step through the code, is it finding the text in the body? If not, maybe the break is a vbLf, not a vbCrLf.

  #14  
Old October 5th 07, 12:24 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Outlook 2003... search for line break char

No, line 7 is not correct. As I said earlier, every folder has a Folders collection, and you need to work with the Folders collection of the Inbox to return your folder:

Set fld = Application.Session.GetDefaultFolder(olFolderInbox )
Set fld = fld.Folders("BUILDER BOOK TEST")

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Ben Bradley" wrote in message ...
Hi Sue

When I initially tried your version of the script, the msg box saying "I
found one!" popped up several times.

So line 8 is obviously returning true at some point.


So this is what I've modified the code to:

01 Sub DoSearch()
02 Dim fld As Outlook.MAPIFolder
03 Dim itm As Object
04 Dim strFind As String
05 On Error Resume Next
06 Set fld = Application.Session.GetDefaultFolder(olFolderInbox )
07 'Set fld = Application.Session.Folders("BUILDER BOOK TEST")
08 strFind = "double-sized listing?" & vbCrLf & "Yes"
09 ' or vbLf it's line feed not a complete CRLF
10 For Each itm In fld.Items
11 If InStr(1, Item.Body, strFind, vbTextCompare) 0 Then
12 MsgBox "You found one!"
13 itm.FlagStatus = olFlagMarked
14 itm.FlagIcon = olYellowFlagIcon
15 itm.Save
16 End If
17 Next
18 Set itm = Nothing
19 Set fld = Nothing
20 End Sub


When I run the above macro all it seems to do is flag all the messages
in my inbox to a yellow flag.

Note lines 6/7 where I'm trying to specify the folder.
Line 6 was your initial example, which seems to flag all messages in the
inbox as yellow.
Line 7 is my attempt which doesn't do anything... running the macro the
screen flickers a bit then just returns to the macro screen.

Is my line 7 syntax correct?


Thanks
Ben


Sue Mosher [MVP-Outlook] wrote:
Do I need to specify that it's actually a sub-folder within my Inbox?


Absolutely, using the Folders collection of the Inbox folder, not the Namespace object.

You can't just set an icon. You must also actually flag the messages. That involves setting the FlagStatus property to olFlagMarked.

If you step through the code, is it finding the text in the body? If not, maybe the break is a vbLf, not a vbCrLf.

  #15  
Old October 5th 07, 04:44 PM posted to microsoft.public.outlook.program_vba
Ben Bradley
external usenet poster
 
Posts: 9
Default Outlook 2003... search for line break char

Hi Sue

Ah ok, that's got me back on the right track.

Just tried it and it just flagged every single message in that BUILDER
BOOK TEST folder with a yellow flag.

Then I tried changing it from vbCrLf to vbLf and the same happened... it
flagged all the messages yellow.

So the only remaining problem is to get the macro to match the messages
correctly.

Any ideas?


Thanks
Ben


Sue Mosher [MVP-Outlook] wrote:
No, line 7 is not correct. As I said earlier, every folder has a Folders collection, and you need to work with the Folders collection of the Inbox to return your folder:

Set fld = Application.Session.GetDefaultFolder(olFolderInbox )
Set fld = fld.Folders("BUILDER BOOK TEST")

  #16  
Old October 5th 07, 07:28 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Outlook 2003... search for line break char

You're the only one who can walk through the code to see where the matches are occurring -- literally, at what position Instr() says the match appears in the text -- and then examine the text to see what's going on.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Ben Bradley" wrote in message ...
Hi Sue

Ah ok, that's got me back on the right track.

Just tried it and it just flagged every single message in that BUILDER
BOOK TEST folder with a yellow flag.

Then I tried changing it from vbCrLf to vbLf and the same happened... it
flagged all the messages yellow.

So the only remaining problem is to get the macro to match the messages
correctly.

Any ideas?


Thanks
Ben


Sue Mosher [MVP-Outlook] wrote:
No, line 7 is not correct. As I said earlier, every folder has a Folders collection, and you need to work with the Folders collection of the Inbox to return your folder:

Set fld = Application.Session.GetDefaultFolder(olFolderInbox )
Set fld = fld.Folders("BUILDER BOOK TEST")

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2007: How to break vertical line in reply to message? [email protected] Outlook - General Queries 1 October 5th 07 09:15 PM
Outlook 2003... search for line break char Ben Bradley Outlook - General Queries 0 September 24th 07 04:29 PM
Outlook 2003 - Search folders - adding criteria to an old mail search? Dustin Emhart Outlook - General Queries 0 December 20th 06 02:39 PM
how do I break up a large attachment that I am sending in Outlook roger Outlook - Installation 1 April 19th 06 08:11 PM
How to input line break in the body of an email defined in vb. Xluser@work Outlook and VBA 1 February 22nd 06 02:20 PM


All times are GMT +1. The time now is 11:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.