Link to home
Start Free TrialLog in
Avatar of Bigbill93638
Bigbill93638

asked on

need line to add to script in outlook

Need line of script to forward email to bigbill99.3fc@m.evernote.com for outlook 2010
Avatar of gbanik
gbanik
Flag of India image

Here's your code...
Option Explicit
Private Const sForwardAddr As String = "bigbill99.3fc@m.evernote.com"

Public Sub ForwardAllSelectedMails()
   On Error Resume Next
    Dim objItem As Outlook.MailItem

    If Application.ActiveExplorer.Selection.Count = 0 Then
        Exit Sub
    End If

    For Each objItem In Application.ActiveExplorer.Selection
        If objItem.Class = olMail Then
            Set objItem = objItem.Forward
            objItem.To = sForwardAddr
            objItem.Send
        End If
    Next
    
End Sub

Open in new window

Avatar of Chris Bottomley
Adapting from the earlier rule then how about:

Note if the subject is to be unchanged on the forward then delete the first two lines and enable the last two

Chris
Sub Q26638986(Item As MailItem)
dim mai as object

    Item.Subject = Item.Subject & " @quotes #quotes"
    Item.Save

    Set mai = objItem.Forward
    mai.To = bigbill99.3fc@m.evernote.com
    mai.Send

'    Item.Subject = Item.Subject & " @quotes #quotes"
'    Item.Save

 
End Sub

Open in new window

Avatar of Bigbill93638
Bigbill93638

ASKER

chris it gives me an error at the . in the email address and says compile error expected end of sub
@Bigbill93638, did the code piece I suggested work for you?
no, the first part works, then it doesn't forward. as below

Sub Q26638986(Item As MailItem)
    Item.Subject = Item.Subject & " @quotes #quotes"
    Item.Save
Option Explicit
Private Const sForwardAddr As String = "bigbill99.3fc@m.evernote.com"

Public Sub ForwardAllSelectedMails()
   On Error Resume Next
    Dim objItem As Outlook.MailItem

    If Application.ActiveExplorer.Selection.Count = 0 Then
        Exit Sub
    End If

    For Each objItem In Application.ActiveExplorer.Selection
        If objItem.Class = olMail Then
            Set objItem = objItem.Forward
            objItem.To = sForwardAddr
            objItem.Send
        End If
    Next
   
End Sub
OOps missed a bit


Can't test currently as I haven't installed office in the Windows partition and cant enable macros in the Mac version .... still, note to self must request attention on my Q!.

Chris
ub Q26638986(Item As MailItem)
dim mai as object

    Item.Subject = Item.Subject & " @quotes #quotes"
    Item.Save

    Set mai = objItem.Forward
    mai.To = "bigbill99.3fc@m.evernote.com"
    mai.Send

'    Item.Subject = Item.Subject & " @quotes #quotes"
'    Item.Save

 
End Sub

Open in new window

@Bigbill93638, thats not the code I posted. Can you please check my code (posted again below)? I have rechecked and it seems this may be what u want.
Option Explicit
Private Const sForwardAddr As String = "bigbill99.3fc@m.evernote.com"

Public Sub ForwardAllSelectedMails()
   On Error Resume Next
    Dim objItem As Outlook.MailItem

    If Application.ActiveExplorer.Selection.Count = 0 Then
        Exit Sub
    End If

    For Each objItem In Application.ActiveExplorer.Selection
        If objItem.Class = olMail Then
            Set objItem = objItem.Forward
            objItem.To = sForwardAddr
            objItem.Send
        End If
    Next
    
End Sub

Open in new window

qbanik, I need to add what you did to what I have in order for it to work, the first part codes it for evernote the second part (what you are doing) sends it. Can you make that work?
Nothing from my post?

Chris
Sub Q26638986(Item As MailItem)
dim mai as object

    Item.Subject = Item.Subject & " @quotes #quotes"
    Item.Save

    Set mai = objItem.Forward
    mai.To = "bigbill99.3fc@m.evernote.com"
    mai.Send

'    Item.Subject = Item.Subject & " @quotes #quotes"
'    Item.Save

 
End Sub

Open in new window

Chris, no it doesn't give me the error but it doesn't forward either.
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked, thanks!
Sorry about the error, the problem with cut and paste from an object file copy.

Chris