Link to home
Start Free TrialLog in
Avatar of dneebrkr
dneebrkr

asked on

Rules in O2K3

Hi,

Can I somehow create a rule that forward a message to a distribution group but puts all receipients in the BCC field?

I tried it in VBA but I just can't set the receipient type to BCC:

Sub FwdFun()

    Dim myItem   As Object
    Dim myolApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Outlook.Selection
    Dim oForward As MailItem
     
    On Error Resume Next
    Set myOlExp = myolApp.ActiveExplorer
    Set myOlSel = myOlExp.Selection
   
 For Each myItem In myOlSel
     
    If TypeName(myItem) = "MailItem" Then
        Dim RCP As Recipient
        Set RCP = myItem.Recipients.Add("admin@ama.co.il")
        RCP.Type = olBCC
        Set oForward = myItem.Forward
        oForward.Recipients.Add RCP
        oForward.Send
        Set oForward = Nothing
        Set RCP = Nothing
    End If
            myItem.Save
    Next
   
    Set myItem = Nothing
    Set myolApp = Nothing
    Set myOlExp = Nothing
    Set myOlSel = Nothing
   
End Sub
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America 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
Avatar of dneebrkr
dneebrkr

ASKER

Hi BlueDevilFan,

10x it works. This is the Script: (Do you have any idea how to make Outlook to send the e-mails through a specific account)

Sub FwdFun()
   
    Dim myItem As Object
    Dim myolApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Outlook.Selection
    Dim oForward As MailItem
    Dim RCP_STR As String

    RCP_STR = InputBox("Destination", "MASS FORWARD", "<>")
    On Error Resume Next
    Set myOlExp = myolApp.ActiveExplorer
    Set myOlSel = myOlExp.Selection
     
    For Each myItem In myOlSel
     
    If TypeName(myItem) = "MailItem" Then
        Set oForward = myItem.Forward
        oForward.BCC = RCP_STR
        oForward.se
        oForward.Send
        Set oForward = Nothing
    End If
        myItem.Body
        myItem.Save
    Next
   
    Set myItem = Nothing
    Set myolApp = Nothing
    Set myOlExp = Nothing
    Set myOlSel = Nothing
   
End Sub
Sorry, I lost track of this question.  Here's how to select a particular account.  Change 3 in the code below to the number corresponding to the account you want to use.  Position 1 will always be the default account.  

Sub ChooseSendThroughAccount()
    Dim olkInspector As Outlook.Inspector, _
        ofcBar As Office.CommandBar, _
        ofcButton As Office.CommandBarPopup, _
        ofcCmdButton As Office.CommandBarButton
    Set olkInspector = Application.ActiveInspector
    Set ofcBar = olkInspector.CommandBars("Standard")
    Set ofcButton = ofcBar.Controls(3)
    ofcButton.Controls(3).Execute
    Set ofcButton = Nothing
    Set ofcBar = Nothing
    Set olkInspector = Nothing
End Sub
BlueDevilFan,

10x,

But it's not working- nothing really changes.

While debugging this is where it gets the first error:
Set ofcBar = olkInspector.CommandBars("Standard")

Run time error '91':

Objext variable or With block variable not set
Did you have a message open at the time?
NO
A message has to be open for that code to work.  Them menu items it keys on are only available when a message window is open.  There are no other ways I know of to choose the send through account.
I tried using the function 'oForward.Display' right before calling to the 'ChooseSendThroughAccount' Sub.
it opens the selected message but it keeps on sending the message via the default account.

If I want to set the account manually - I click the 'Account' DD menu and then choose an account - how dows your code reflects these actions?
> I click the 'Account' DD menu and then choose an account
That's exactly what the code does.  It simulates a click on that menu and then selects the item in the list corresponding to the number passed.  There may be confusion over the numbers.  If you go through these steps manually you see something like this with the list pulled down:

    Account A
    -----------
    1 Account A
    2 Account B

You might think that passing a 2 would get you Account A.  Instead it gets the second instance of Account A.  When deciding what number to pass count the entries from the top down and ignore the numbers that appear onscreen.  In this example the choices are

    1  Account A
    2  Account A
    3  Account B

Make sense?