Solved

Macro Question

Posted on 2010-09-03
7
259 Views
Last Modified: 2012-05-10
I would like to change this macro around so that it fits the format of the list already made.

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_26435925.html#a33564683

 I tried to fit it in but encountered some errors with it. Here it is:

Sub Artwork()
Dim para As Variant
Dim strArray() As String
Dim mai As Object
Dim strSearchFor() As Variant: strSearchFor = Array("> Email:", "> Shipping Company:", "> Tracking Number:", "> Estimated Arrival Date:", "> Contact:", "> Company Name:")
Dim strResults() As String
Dim elem As Integer
Const str2 As String = ""
Const str3 As String = ""
Const str4 As String = ""
   
    ReDim strResults(UBound(strSearchFor))
    If TypeName(Application.ActiveWindow) = "Explorer" Then
        Set mai = Application.ActiveExplorer.Selection.Item(1)
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
            Set mai = Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If
    With mai
        strArray = Split(.Body, vbCrLf)
        For Each para In strArray
            If para <> "" Then
                For elem = LBound(strSearchFor) To UBound(strSearchFor)
                    If LCase(Left(para, Len(strSearchFor(elem)))) = LCase(strSearchFor(elem)) Then strResults(elem) = Trim(Split(para, ":")(1))
                Next
            End If
        Next
    End With
    Set mai = Nothing
    If strResults(0) = "" Then Exit Sub
    ' Only proceed if we have an email address!
    Set mai = Application.CreateItem(olMailItem)
    With mai
        .To = strResults(0)
        .Subject = mai.Subject
        .Body = "Dear " & Split(strResults(4) & " ", " ")(0) & vbCrLf & vbCrLf & _
            "Please find attached a photo of the first unit our production has made of your order and kindly confirm it is to your satisfaction before we proceed. If you have any other questions with this order, do not hesitate to ask. " & vbCrLf & vbCrLf & _
            "Best regards," & vbCrLf & _
                   "Derek" & vbCrLf & vbCrLf & _
                   "Derek Sheahan | Sales Manager TLN Group| tlngroup.com|" & vbCrLf & _
                   "|derek@tlngroup.com | Phone: (1800) 385 8156 | Fax : (1888) 429 7748" & vbCrLf & _
                   "420-2906 West Broadway, Vancouver , BC, V6K 2G8, Canada"
        .Display
    End With

End Sub

I would like to change this to editone and also make one change to it so that it takes the attachments from the current mail selected and adds them to the new mail being created.


Many thanks,

Derek
0
Comment
Question by:TLN_CANADA
  • 4
  • 3
7 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 33600054
If I follow then something like this?

Chris
Sub EditOne(mai as variant)

Dim para As Variant

Dim strArray() As String

Dim nuMai As Object

Dim strSearchFor() As Variant: strSearchFor = Array("> Email:", "> Shipping Company:", "> Tracking Number:", "> Estimated Arrival Date:", "> Contact:", "> Company Name:")

Dim strResults() As String

Dim elem As Integer

Const str2 As String = ""

Const str3 As String = ""

Const str4 As String = ""

    

    ReDim strResults(UBound(strSearchFor))

'    If TypeName(Application.ActiveWindow) = "Explorer" Then

'        Set mai = Application.ActiveExplorer.Selection.Item(1)

'    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then

'            Set mai = Application.ActiveInspector.CurrentItem

'    Else

'        Exit Sub

'    End If

    With mai

        strArray = Split(.Body, vbCrLf)

        For Each para In strArray

            If para <> "" Then

                For elem = LBound(strSearchFor) To UBound(strSearchFor)

                    If LCase(Left(para, Len(strSearchFor(elem)))) = LCase(strSearchFor(elem)) Then strResults(elem) = Trim(Split(para, ":")(1))

                Next

            End If

        Next

    End With

'    Set mai = Nothing

    If strResults(0) = "" Then Exit Sub

    ' Only proceed if we have an email address!

    Set numai = Application.CreateItem(olMailItem)

    With numai

    CopyAttachments maiOrig, numai

        .To = strResults(0)

        .Subject = mai.Subject

        .Body = "Dear " & Split(strResults(4) & " ", " ")(0) & vbCrLf & vbCrLf & _

            "Please find attached a photo of the first unit our production has made of your order and kindly confirm it is to your satisfaction before we proceed. If you have any other questions with this order, do not hesitate to ask. " & vbCrLf & vbCrLf & _

            "Best regards," & vbCrLf & _

                   "Derek" & vbCrLf & vbCrLf & _

                   "Derek Sheahan | Sales Manager TLN Group| tlngroup.com|" & vbCrLf & _

                   "|derek@tlngroup.com | Phone: (1800) 385 8156 | Fax : (1888) 429 7748" & vbCrLf & _

                   "420-2906 West Broadway, Vancouver , BC, V6K 2G8, Canada"

        .Display

    End With



End Sub

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 33600131
Thanks Chris,

It is giving an error saying object required and pointing to the line :

 For Each objAtt In objSourceItem.Attachments

of this sub :

Sub CopyAttachments(objSourceItem, objTargetItem)
' See outlookcode.com
Dim FSO As Object
Dim fldTemp As Object
Dim strPath As String
Dim strFile As String
Dim objAtt As Object
Dim fileType As String
 
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set fldTemp = FSO.GetSpecialFolder(2) 'Temp
   strPath = fldTemp.Path & "\"
   For Each objAtt In objSourceItem.Attachments
      fileType = LCase(Right(objAtt.FileName, Len(objAtt.FileName) - InStrRev(objAtt.FileName, ".")))
        strFile = strPath & objAtt.FileName
        objAtt.SaveAsFile strFile
        objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
        FSO.DeleteFile strFile
   Next
 
   Set fldTemp = Nothing
   Set FSO = Nothing
End Sub


I think you added this sub also on a previous question?

Thanks,

Derek
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 33600210
>>> I think you added this sub also on a previous question?

Indeed we did.

WHat is the object being 'processed'? a mail item an invite or what?

Chris
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 33600225
OOOOOOOOPS!

Too literal a cut and paste.

Chris
Sub EditOne(mai as variant)

Dim para As Variant

Dim strArray() As String

Dim nuMai As Object

Dim strSearchFor() As Variant: strSearchFor = Array("> Email:", "> Shipping Company:", "> Tracking Number:", "> Estimated Arrival Date:", "> Contact:", "> Company Name:")

Dim strResults() As String

Dim elem As Integer

Const str2 As String = ""

Const str3 As String = ""

Const str4 As String = ""

    

    ReDim strResults(UBound(strSearchFor))

'    If TypeName(Application.ActiveWindow) = "Explorer" Then

'        Set mai = Application.ActiveExplorer.Selection.Item(1)

'    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then

'            Set mai = Application.ActiveInspector.CurrentItem

'    Else

'        Exit Sub

'    End If

    With mai

        strArray = Split(.Body, vbCrLf)

        For Each para In strArray

            If para <> "" Then

                For elem = LBound(strSearchFor) To UBound(strSearchFor)

                    If LCase(Left(para, Len(strSearchFor(elem)))) = LCase(strSearchFor(elem)) Then strResults(elem) = Trim(Split(para, ":")(1))

                Next

            End If

        Next

    End With

'    Set mai = Nothing

    If strResults(0) = "" Then Exit Sub

    ' Only proceed if we have an email address!

    Set numai = Application.CreateItem(olMailItem)

    With numai

    CopyAttachments mai, numai

        .To = strResults(0)

        .Subject = mai.Subject

        .Body = "Dear " & Split(strResults(4) & " ", " ")(0) & vbCrLf & vbCrLf & _

            "Please find attached a photo of the first unit our production has made of your order and kindly confirm it is to your satisfaction before we proceed. If you have any other questions with this order, do not hesitate to ask. " & vbCrLf & vbCrLf & _

            "Best regards," & vbCrLf & _

                   "Derek" & vbCrLf & vbCrLf & _

                   "Derek Sheahan | Sales Manager TLN Group| tlngroup.com|" & vbCrLf & _

                   "|derek@tlngroup.com | Phone: (1800) 385 8156 | Fax : (1888) 429 7748" & vbCrLf & _

                   "420-2906 West Broadway, Vancouver , BC, V6K 2G8, Canada"

        .Display

    End With



End Sub

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 33600329
Excellent ! Working now :) One final change to this.

If I could change the subject to the following that would be great :

SUPPLIER NAME - COMPANY NAME - First Unit Confirmation Needed

The lines in the email where I am taking this from are:

> Supplier Order Number: FTN-A135

> Company Name: Test

So the subject would look like: FTN-A135 - Test - First Unit Confirmation Needed

You did something very similar to this on the last macro. I think this is the last thing and then all done. I'll have to ask my boss to add you to the payroll you've helped us out so much!!

Derek
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 33600398

Sub EditOne(mai as variant)

Dim para As Variant

Dim strArray() As String

Dim nuMai As Object

Dim strSearchFor() As Variant: strSearchFor = Array("> Email:", "> Shipping Company:", "> Tracking Number:", "> Estimated Arrival Date:", "> Contact:", "> Company Name:", "> Supplier Order Number:")

Dim strResults() As String

Dim elem As Integer

Const str2 As String = ""

Const str3 As String = ""

Const str4 As String = ""

    

    ReDim strResults(UBound(strSearchFor))

'    If TypeName(Application.ActiveWindow) = "Explorer" Then

'        Set mai = Application.ActiveExplorer.Selection.Item(1)

'    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then

'            Set mai = Application.ActiveInspector.CurrentItem

'    Else

'        Exit Sub

'    End If

    With mai

        strArray = Split(.Body, vbCrLf)

        For Each para In strArray

            If para <> "" Then

                For elem = LBound(strSearchFor) To UBound(strSearchFor)

                    If LCase(Left(para, Len(strSearchFor(elem)))) = LCase(strSearchFor(elem)) Then strResults(elem) = Trim(Split(para, ":")(1))

                Next

            End If

        Next

    End With

'    Set mai = Nothing

    If strResults(0) = "" Then Exit Sub

    ' Only proceed if we have an email address!

    Set numai = Application.CreateItem(olMailItem)

    With numai

    CopyAttachments mai, numai

        .To = strResults(0)

'        .Subject = mai.Subject

        .Subject = strResults(6) & " - " & strResults(5) & " - First Unit Confirmation Needed"

        .Body = "Dear " & Split(strResults(4) & " ", " ")(0) & vbCrLf & vbCrLf & _

            "Please find attached a photo of the first unit our production has made of your order and kindly confirm it is to your satisfaction before we proceed. If you have any other questions with this order, do not hesitate to ask. " & vbCrLf & vbCrLf & _

            "Best regards," & vbCrLf & _

                   "Derek" & vbCrLf & vbCrLf & _

                   "Derek Sheahan | Sales Manager TLN Group| tlngroup.com|" & vbCrLf & _

                   "|derek@tlngroup.com | Phone: (1800) 385 8156 | Fax : (1888) 429 7748" & vbCrLf & _

                   "420-2906 West Broadway, Vancouver , BC, V6K 2G8, Canada"

        .Display

    End With



End Sub

Open in new window

0
 

Author Closing Comment

by:TLN_CANADA
ID: 33600438
Thank you so much, this is very helpful!
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't know how to downgrade, my instructions below should be helpful.
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now