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

UserForm and ordering variables



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 27th 10, 09:20 PM posted to microsoft.public.outlook.program_vba
Chris
external usenet poster
 
Posts: 280
Default UserForm and ordering variables

I need help with ordering an set of variables (strSend,strSubj,StrTime) and
keeping them in that order. I use a userform to allow the user to select one
of the ten formats and assign the order to the variable FileNameFormat
(FileNameFormat = strTime & "_" & strSend & "_" & strSubj). The problem is
that the FileNameFormat takes the values of the variables once and will not
update with the new data as the loop is run (NewFileName = FileNameFormat &
".msg"). Is there a way to store the order of variables in another variable
to be able to assign the values of those stored variables as they change?

-----Variable Declarations-----
Global FileNameFormat As Variant
Global strSubj, strTime, strSend, mailClassCheck, EmailPath As String
Global RunOnce As Boolean
-----Module Code-----
Public Sub ExportSAR()

Dim TheEmail As Object
Dim ReportEmail As ReportItem
Dim eItem As Outlook.Items
Dim EmailNS As NameSpace
Dim fldrCount, EmailPath2, NbrItem, myfolder
Dim NewFileName, ReportHeader As String
Dim Cats
Dim CheckErr, Exists As Boolean

CheckErr = False
RunOnce = False
Set EmailNS = Application.GetNamespace("MAPI")
Set myfolder = Application.ActiveExplorer.CurrentFolder
NbrItem = myfolder.Items.Count
On Error GoTo Error_Handler

EmailPath = BrowseForFolderShell
'FileName.Show
'MsgBox FileNameFormat
'MsgBox EmailPath, vbOKCancel
'EmailPath = InputBox("Enter the save folder location:", "Email Save
Path", CurDir)
For i = 1 To NbrItem
Set TheEmail = Application.ActiveExplorer.CurrentFolder.Items.Ite m(i)
'MsgBox Len(TheEmail.SenderName) & Chr$(13) & Len(TheEmail.Subject) &
Chr$(13) & Len(TheEmail.ReceivedTime)
'MsgBox TheEmail.SenderName & Chr$(13) & TheEmail.Subject & Chr$(13) &
TheEmail.ReceivedTime
TheEmail.Categories = TheEmail.Categories & ";" & "Red Category"
mailClassCheck = TheEmail.MessageClass
If Left(mailClassCheck, 6) = "REPORT" Or Left(mailClassCheck, 6) =
"Report" Then
Set ReportEmail =
Application.ActiveExplorer.CurrentFolder.Items.Ite m(i)
If ReportEmail.Subject = "" Then strSubj = "no subject"
If Right(ReportEmail.MessageClass, 2) = "DR" Then ReportHeader =
"DeliveryReport" Else ReportHeader = "Read Receipt"

strSubj = Replace(ReportEmail.Subject, "/", "-")
strSubj = Replace(strSubj, "\", "-")
strSubj = Replace(strSubj, ":", "--")
strSubj = Replace(strSubj, "?", sReplace)
strSubj = Replace(strSubj, "*", sReplace)
strSubj = Replace(strSubj, Chr$(34), sReplace)
'strSubj = Replace(strSubj, Chr$(9), sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "|", sReplace)
strTime = Replace(ReportEmail.CreationTime, "/", "-")
strTime = Replace(strTime, "\", "-")
strTime = Replace(strTime, ":", ".")
strTime = Replace(strTime, "?", sReplace)
strTime = Replace(strTime, "*", sReplace)
strTime = Replace(strTime, Chr$(34), sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "|", sReplace)
NewFileName = ReportHeader & "_" & strSubj & strTime & ".msg"
MsgBox FileNameFormat
If NewFileName "" Then
ReportEmail.SaveAs EmailPath & NewFileName, olMSG
Else
MsgBox "No file name was entered. Operation aborted.", 64,
"Cancel Operation"
Exit Sub
End If
GoTo Step1
End If
If TheEmail.Subject = "" Then strSubj = "no subject"

strSend = Replace(TheEmail.SenderName, "/", "-")
strSend = Replace(strSend, "\", "-")
strSend = Replace(strSend, ":", "--")
strSend = Replace(strSend, "?", sReplace)
strSend = Replace(strSend, "*", sReplace)
strSend = Replace(strSend, Chr$(34), sReplace)
strSend = Replace(strSend, "", sReplace)
strSend = Replace(strSend, "", sReplace)
strSend = Replace(strSend, "|", sReplace)
strSubj = Replace(TheEmail.Subject, "/", "-")
strSubj = Replace(strSubj, "\", "-")
strSubj = Replace(strSubj, ":", "--")
strSubj = Replace(strSubj, "?", sReplace)
strSubj = Replace(strSubj, "*", sReplace)
strSubj = Replace(strSubj, Chr$(34), sReplace)
'strSubj = Replace(strSubj, Chr$(9), sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "|", sReplace)
strSubj = Replace(strSubj, "{", sReplace)
strSubj = Replace(strSubj, "}", sReplace)
strSubj = Replace(strSubj, " ", sReplace)
strTime = Replace(TheEmail.ReceivedTime, "/", "-")
strTime = Replace(strTime, "\", "-")
strTime = Replace(strTime, ":", ".")
strTime = Replace(strTime, "?", sReplace)
strTime = Replace(strTime, "*", sReplace)
strTime = Replace(strTime, Chr$(34), sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "|", sReplace)
'NewFileName = strSend & "_" & strTime & "_" & strSubj & ".msg"
If RunOnce = False Then
FileName.Show
MsgBox FileNameFormat
RunOnce = True
End If
NewFileName = FileNameFormat & ".msg"
If NewFileName "" Then
If Len(NewFileName) 160 Then
TooLong:
NewFileName = InputBox("Please Enter a New File Name that is
shorter than 161 characters." & Chr$(13) & "Current file name is " &
Len(NewFileName) & "characters.", _
"File Name Too Long", NewFileName)
If Len(NewFileName) 160 Then
MsgBox "File name is still too long." & Chr$(13) & "Current file
name is " & Len(NewFileName) & "characters.", vbOKOnly, "File Name is Too
Long"
GoTo TooLong
Else
TheEmail.SaveAs EmailPath & NewFileName, olMSG
End If
Else
TheEmail.SaveAs EmailPath & NewFileName, olMSG
End If
Else
MsgBox "No file name was entered. Operation aborted.", 64,
"Cancel Operation"
Exit Sub
End If
Step1:
strSubj = ""
strTime = ""
Next i
GoTo Done

Error_Handler:
If TheEmail Is Nothing Then
MsgBox Err.Number & ":" & Err.Description
TheEmail.Categories = TheEmail.Categories & ";" & "Not Copied"
Else
MsgBox TheEmail.MessageClass & Chr$(13) & Len(NewFileName) & Chr$(13) &
Chr$(13) & strSend & Chr$(13) & strTime & Chr$(13) & TheEmail.Subject &
Chr$(13) & strSubj & Chr$(13) & Err.Number & ": " & Err.Description
TheEmail.Categories = TheEmail.Categories & ";" & "Not Copied"
TheEmail.Save
End If
Resume Next

Done:
End Sub

-----UserForm Code-----
Private Sub Submit_Click()
Select Case FileFormat
Case DateSendSubj
FileNameFormat = strTime & "_" & strSend & "_" & strSubj
Case DateSubj
FileNameFormat = strTime & "_" & strSubj
Case DateSubjSend
FileNameFormat = strTime & "_" & strSubj & "_" & strSend
Case SendDateSubj
FileNameFormat = strSend & "_" & strTime & "_" & strSubj
Case SendSubj
FileNameFormat = strSend & "_" & strSubj
Case SendSubjDate
FileNameFormat = strSend & "_" & strSubj & "_" & strTime
Case SubjDate
FileNameFormat = strSubj & "_" & strTime
Case SubjDateSend
FileNameFormat = strSubj & "_" & strTime & "_" & strSend
Case SubjSend
FileNameFormat = strSubj & "_" & strSend
Case SubjSendDate
FileNameFormat = strSubj & "_" & strSend & "_" & strTime
End Select
Me.Hide
End Sub

  #2  
Old May 27th 10, 10:49 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_4_]
external usenet poster
 
Posts: 552
Default UserForm and ordering variables

Why not just declare the variables strTime, strSend, and strSubj as global
variables?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54



"Chris" wrote:

I need help with ordering an set of variables (strSend,strSubj,StrTime) and
keeping them in that order. I use a userform to allow the user to select one
of the ten formats and assign the order to the variable FileNameFormat
(FileNameFormat = strTime & "_" & strSend & "_" & strSubj). The problem is
that the FileNameFormat takes the values of the variables once and will not
update with the new data as the loop is run (NewFileName = FileNameFormat &
".msg"). Is there a way to store the order of variables in another variable
to be able to assign the values of those stored variables as they change?

-----Variable Declarations-----
Global FileNameFormat As Variant
Global strSubj, strTime, strSend, mailClassCheck, EmailPath As String
Global RunOnce As Boolean
-----Module Code-----
Public Sub ExportSAR()

Dim TheEmail As Object
Dim ReportEmail As ReportItem
Dim eItem As Outlook.Items
Dim EmailNS As NameSpace
Dim fldrCount, EmailPath2, NbrItem, myfolder
Dim NewFileName, ReportHeader As String
Dim Cats
Dim CheckErr, Exists As Boolean

CheckErr = False
RunOnce = False
Set EmailNS = Application.GetNamespace("MAPI")
Set myfolder = Application.ActiveExplorer.CurrentFolder
NbrItem = myfolder.Items.Count
On Error GoTo Error_Handler

EmailPath = BrowseForFolderShell
'FileName.Show
'MsgBox FileNameFormat
'MsgBox EmailPath, vbOKCancel
'EmailPath = InputBox("Enter the save folder location:", "Email Save
Path", CurDir)
For i = 1 To NbrItem
Set TheEmail = Application.ActiveExplorer.CurrentFolder.Items.Ite m(i)
'MsgBox Len(TheEmail.SenderName) & Chr$(13) & Len(TheEmail.Subject) &
Chr$(13) & Len(TheEmail.ReceivedTime)
'MsgBox TheEmail.SenderName & Chr$(13) & TheEmail.Subject & Chr$(13) &
TheEmail.ReceivedTime
TheEmail.Categories = TheEmail.Categories & ";" & "Red Category"
mailClassCheck = TheEmail.MessageClass
If Left(mailClassCheck, 6) = "REPORT" Or Left(mailClassCheck, 6) =
"Report" Then
Set ReportEmail =
Application.ActiveExplorer.CurrentFolder.Items.Ite m(i)
If ReportEmail.Subject = "" Then strSubj = "no subject"
If Right(ReportEmail.MessageClass, 2) = "DR" Then ReportHeader =
"DeliveryReport" Else ReportHeader = "Read Receipt"

strSubj = Replace(ReportEmail.Subject, "/", "-")
strSubj = Replace(strSubj, "\", "-")
strSubj = Replace(strSubj, ":", "--")
strSubj = Replace(strSubj, "?", sReplace)
strSubj = Replace(strSubj, "*", sReplace)
strSubj = Replace(strSubj, Chr$(34), sReplace)
'strSubj = Replace(strSubj, Chr$(9), sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "|", sReplace)
strTime = Replace(ReportEmail.CreationTime, "/", "-")
strTime = Replace(strTime, "\", "-")
strTime = Replace(strTime, ":", ".")
strTime = Replace(strTime, "?", sReplace)
strTime = Replace(strTime, "*", sReplace)
strTime = Replace(strTime, Chr$(34), sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "|", sReplace)
NewFileName = ReportHeader & "_" & strSubj & strTime & ".msg"
MsgBox FileNameFormat
If NewFileName "" Then
ReportEmail.SaveAs EmailPath & NewFileName, olMSG
Else
MsgBox "No file name was entered. Operation aborted.", 64,
"Cancel Operation"
Exit Sub
End If
GoTo Step1
End If
If TheEmail.Subject = "" Then strSubj = "no subject"

strSend = Replace(TheEmail.SenderName, "/", "-")
strSend = Replace(strSend, "\", "-")
strSend = Replace(strSend, ":", "--")
strSend = Replace(strSend, "?", sReplace)
strSend = Replace(strSend, "*", sReplace)
strSend = Replace(strSend, Chr$(34), sReplace)
strSend = Replace(strSend, "", sReplace)
strSend = Replace(strSend, "", sReplace)
strSend = Replace(strSend, "|", sReplace)
strSubj = Replace(TheEmail.Subject, "/", "-")
strSubj = Replace(strSubj, "\", "-")
strSubj = Replace(strSubj, ":", "--")
strSubj = Replace(strSubj, "?", sReplace)
strSubj = Replace(strSubj, "*", sReplace)
strSubj = Replace(strSubj, Chr$(34), sReplace)
'strSubj = Replace(strSubj, Chr$(9), sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "", sReplace)
strSubj = Replace(strSubj, "|", sReplace)
strSubj = Replace(strSubj, "{", sReplace)
strSubj = Replace(strSubj, "}", sReplace)
strSubj = Replace(strSubj, " ", sReplace)
strTime = Replace(TheEmail.ReceivedTime, "/", "-")
strTime = Replace(strTime, "\", "-")
strTime = Replace(strTime, ":", ".")
strTime = Replace(strTime, "?", sReplace)
strTime = Replace(strTime, "*", sReplace)
strTime = Replace(strTime, Chr$(34), sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "", sReplace)
strTime = Replace(strTime, "|", sReplace)
'NewFileName = strSend & "_" & strTime & "_" & strSubj & ".msg"
If RunOnce = False Then
FileName.Show
MsgBox FileNameFormat
RunOnce = True
End If
NewFileName = FileNameFormat & ".msg"
If NewFileName "" Then
If Len(NewFileName) 160 Then
TooLong:
NewFileName = InputBox("Please Enter a New File Name that is
shorter than 161 characters." & Chr$(13) & "Current file name is " &
Len(NewFileName) & "characters.", _
"File Name Too Long", NewFileName)
If Len(NewFileName) 160 Then
MsgBox "File name is still too long." & Chr$(13) & "Current file
name is " & Len(NewFileName) & "characters.", vbOKOnly, "File Name is Too
Long"
GoTo TooLong
Else
TheEmail.SaveAs EmailPath & NewFileName, olMSG
End If
Else
TheEmail.SaveAs EmailPath & NewFileName, olMSG
End If
Else
MsgBox "No file name was entered. Operation aborted.", 64,
"Cancel Operation"
Exit Sub
End If
Step1:
strSubj = ""
strTime = ""
Next i
GoTo Done

Error_Handler:
If TheEmail Is Nothing Then
MsgBox Err.Number & ":" & Err.Description
TheEmail.Categories = TheEmail.Categories & ";" & "Not Copied"
Else
MsgBox TheEmail.MessageClass & Chr$(13) & Len(NewFileName) & Chr$(13) &
Chr$(13) & strSend & Chr$(13) & strTime & Chr$(13) & TheEmail.Subject &
Chr$(13) & strSubj & Chr$(13) & Err.Number & ": " & Err.Description
TheEmail.Categories = TheEmail.Categories & ";" & "Not Copied"
TheEmail.Save
End If
Resume Next

Done:
End Sub

-----UserForm Code-----
Private Sub Submit_Click()
Select Case FileFormat
Case DateSendSubj
FileNameFormat = strTime & "_" & strSend & "_" & strSubj
Case DateSubj
FileNameFormat = strTime & "_" & strSubj
Case DateSubjSend
FileNameFormat = strTime & "_" & strSubj & "_" & strSend
Case SendDateSubj
FileNameFormat = strSend & "_" & strTime & "_" & strSubj
Case SendSubj
FileNameFormat = strSend & "_" & strSubj
Case SendSubjDate
FileNameFormat = strSend & "_" & strSubj & "_" & strTime
Case SubjDate
FileNameFormat = strSubj & "_" & strTime
Case SubjDateSend
FileNameFormat = strSubj & "_" & strTime & "_" & strSend
Case SubjSend
FileNameFormat = strSubj & "_" & strSend
Case SubjSendDate
FileNameFormat = strSubj & "_" & strSend & "_" & strTime
End Select
Me.Hide
End Sub

 




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
UserForm and ordering variables Chris Outlook and VBA 0 May 27th 10 09:07 PM
Ordering Shared Calendars Diane Poremsky [MVP] Outlook - Calandaring 1 August 4th 09 01:50 AM
Ordering messages by To instead of From Confused Outlook Express 5 June 19th 07 06:55 PM
Global Variables/Session Variables dch3 Outlook and VBA 2 May 31st 07 01:11 PM
Ordering Pizza: *x@y* Outlook Express 0 February 3rd 06 12:02 AM


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