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

Why will this code just change subject to only the fist selecteditem?



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old May 21st 08, 02:24 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Why will this code just change subject to only the fist selected item?

You still aren't saving the item in your loop. Right after this line of
code:

myOlSel.Item(x).Subject = txtA & myOlSel.Item(x).Subject

Put this:

myOlSel.Item(x).Save

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"ExcelLars" wrote in message
...
Private Sub CommandButton1_Click()

Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim strProsjektnrnavn, strProsjektnrnavnDel1,
strProsjektnrnavnDel2 As String
Dim Mdato, Emne As String
Dim x As Integer

Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
On Error Resume Next
strProsjektnrnavnDel1 = ""
strProsjektnrnavnDel2 = ""


strProsjektnrnavnDel1 = ListBox1.Value
strProsjektnrnavnDel2 = ListBox2.Value

If strProsjektnrnavnDel1 = Null Then strProsjektnrnavnDel1 = ""
If strProsjektnrnavnDel2 = Null Then strProsjektnrnavnDel2 = ""

If CheckBox3 = True And CheckBox1 = True Then strProsjektnrnavn =
"[" & strProsjektnrnavnDel1 & "] " & "[" & strProsjektnrnavnDel2 & "]
"
If CheckBox3 = True And CheckBox1 = False Then strProsjektnrnavn =
"[" & strProsjektnrnavnDel1 & "] "
If CheckBox3 = False And CheckBox1 = True Then strProsjektnrnavn =
"[" & strProsjektnrnavnDel2 & "] "
If CheckBox3 = False And CheckBox1 = False Then strProsjektnrnavn
= ""

For x = 1 To myOlSel.Count
Emne = myOlSel.Item(x).Subject
myOlSel.Item(x).Subject = strProsjektnrnavn & Emne
If CheckBox2 = True Then myOlSel.Item(x).Categories =
strProsjektnrnavnDel2
'If CheckBox4 = True Then myOlSel.Item(x).UnRead = False
If CheckBox7 = True Then
'Copies an email message and makes it a Task Item with a Due
Date of today
Dim objMsg As Outlook.MailItem, objTask As Outlook.TaskItem
Set objMsg = Application.ActiveExplorer.Selection.Item(1)
Set objTask = Application.CreateItem(olTaskItem)
objTask.Body = objMsg.Body
objTask.Subject = objMsg.Subject
objTask.DueDate = Now
objTask.Save

Else
End If
If OptionButton1 = True Then myOlSel.Item(x).UnRead = False
If OptionButton2 = True Then myOlSel.Item(x).UnRead = True
If CheckBox5 = True Then
Mdato = Format(Year(myOlSel.Item(x).ReceivedTime), yyyy)
Mdato = Mdato &
Format(Month(myOlSel.Item(x).ReceivedTime), "00")
Mdato = Mdato & Format(Day(myOlSel.Item(x).ReceivedTime),
"00")
Mdato = Mdato & " "
Mdato = Mdato & Format(Hour(myOlSel.Item(x).ReceivedTime),
"00")
Mdato = Mdato &
Format(Minute(myOlSel.Item(x).ReceivedTime), "00")
Mdato = Mdato &
Format(Second(myOlSel.Item(x).ReceivedTime), "00")

Avsendernavn = myOlSel.Item(x).SenderEmailAddress

If Left(Avsendernavn, 10) = "/O=xxxxxxxx" Then
lengde = InStr(Right(Avsendernavn, 5), "=")
Avsendernavn = Mid(Right(Avsendernavn, 5), lengde + 1,
5 - lengde)
Else
End If

Dim ar()
Dim i&
Dim ReplaceBy$
ReplaceBy = "_"
ar = Array(";", ":", ",", "\", "/", "*", "[", "]", "?",
"!", "'", "", "", "|", "$")
'ar = Array(";", ":")
For i = 0 To UBound(ar)
Emne = Replace(1, Emne, ar(i), ReplaceBy, vbTextCompare)
Next

filnavn = Mdato & " " & Avsendernavn & " " & Emne & ".MSG"
txtSti = TextBox1.Value

myOlSel.Item(x).SaveAs txtSti & filnavn, olMSG
txtA = "[A] "
myOlSel.Item(x).Subject = txtA & myOlSel.Item(x).Subject

Else
End If
If CheckBox6 = True Then myOlSel.Item(x).Delete

Next x
End Sub


Ads
  #12  
Old May 21st 08, 11:21 PM posted to microsoft.public.outlook.program_vba
ExcelLars
external usenet poster
 
Posts: 19
Default Why will this code just change subject to only the fist selecteditem?

Sorry i'm newbee to programing. Thank You for all help! Now it works!
 




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
Date/Time Code as tracking # in Subject Line TOMB Outlook and VBA 3 April 29th 08 06:44 AM
ListBox SelectedItem to TextBox JP Outlook - Using Forms 1 August 1st 07 01:42 PM
Code to extract subject line [email protected] Outlook and VBA 3 August 25th 06 06:54 PM
Change subject in all emails DB01 Outlook and VBA 2 May 28th 06 09:24 AM
Change email subject line... silas Outlook Express 1 February 27th 06 11:59 PM


All times are GMT +1. The time now is 03:41 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.