Alan McGowan
Senior Member
- Outlook version
- Outlook 2013 64 bit
- Email Account
- Exchange Server
I have the code below sitting on a module:
the code that sits between the ########## is repeated in several of the modules I have and I would like to put this into its own module that I can then call this new module from each of the other modules. I tried cutting and pasting the block of code into a new module called clean_char (module 2) and replacing this block of code in the module above with the code Call module2.clean_char. However this didn't work. This is the first time I have tried to call one module from another so a bit unsure how to get it working.
Code:
Sub MsgSaver(strPath As String, msgItem As Outlook.MailItem, lngCounter As Long, blnMulti As Boolean)
Dim intC As Integer
Dim intD As Integer
Dim strMsgSubj As String
Dim strMsgTo As String
'Set name to save message to
If UserForm1.CheckBox1.Value = True Then
If UserForm1.g_blnOutgoing = True Then
strMsgSubj = Format(msgItem.senton, "yyyy-mm-dd Hh.Nn.Ss") & " " & "[To " & Left(msgItem.To, 25) & "]" & " " & UserForm1.TextBox9.Value & "_0" & lngCounter & ".msg"
Else 'incoming mail so use from field
strMsgSubj = Format(msgItem.senton, "yyyy-mm-dd Hh.Nn.Ss") & " " & "[From " & msgItem.SenderName & "]" & " " & UserForm1.TextBox9.Value & "_0" & lngCounter & ".msg"
End If
ElseIf blnMulti = True Then
strMsgSubj = msgItem.Subject
If UserForm1.g_blnOutgoing = True Then
strMsgSubj = Format(msgItem.senton, "yyyy-mm-dd Hh.Nn.Ss") & " " & "[To " & Left(msgItem.To, 25) & "]" & " " & strMsgSubj & ".msg"
Else 'incoming mail so use from field
strMsgSubj = Format(msgItem.senton, "yyyy-mm-dd Hh.Nn.Ss") & " " & "[From " & msgItem.SenderName & "]" & " " & strMsgSubj & ".msg"
End If
Else
strMsgSubj = UserForm1.TextBox8.Value & ".msg"
End If
' ##################################
' Clean out characters from Subject which are not permitted in a file name
For intC = 1 To Len(strMsgSubj)
If InStr(1, ":<&>""", Mid(strMsgSubj, intC, 1)) > 0 Then
Mid(strMsgSubj, intC, 1) = "-"
End If
Next intC
For intC = 1 To Len(strMsgSubj)
If InStr(1, "\/|*?", Mid(strMsgSubj, intC, 1)) > 0 Then
Mid(strMsgSubj, intC, 1) = "_"
End If
Next intC
' ##################################
'Save new msg file to defined filename and location
msgItem.SaveAs strPath & strMsgSubj
Set msgItem = Nothing
UserForm1.hide
End Sub
the code that sits between the ########## is repeated in several of the modules I have and I would like to put this into its own module that I can then call this new module from each of the other modules. I tried cutting and pasting the block of code into a new module called clean_char (module 2) and replacing this block of code in the module above with the code Call module2.clean_char. However this didn't work. This is the first time I have tried to call one module from another so a bit unsure how to get it working.