More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

Login

login
password
Remember me

You will need to register and log in if you want to download the source code for the Microsoft Outlook Programming book. The forums and code sharing areas are open to both registered and non-registered visitors.

forum 09-Sep-2010 06:08

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

 

    Page [ 1 ]  
 Code Essentials Printer Friendly Version
Beginner’s section on how to work in the VBA environment, how to work with functions and expressions – generally not specific to Outlook
Topic
How to use macro to call a custom forward form
Good day all, i've got a macro to open a custom form for generating a formated email. Form name is "Form_SR_TEST" for now.

Sub Form_SR()
  strForm = "IPM.NOTE.Form_SR_test"
  Set objFolder = Application.ActiveExplorer.CurrentFolder
  Set objItem = objFolder.Items.Add(strForm)
  objItem.Display
  Item_Open = False
End Sub()

Idealy it would go as follow:

-User click the item they want to forward within outlook.
-User click macro (This is done)

-Somehow Forward the currently selected item to be used in the Custom form i created. (this is where i need help)

-customised the .HTMLbody (this part is all done based on the form, but need to "add" the forwarded text into it)
-Generate a new email with end product (this part is done)



My questions are as follow:

1- How can i allow my macro to Forward the current email selected? (Which property / methode to use)

2- How does it keep the attachments and text of message? (Which variable / value should i carry over?)


 

  02-Nov-2009  11:53
  02-Nov-2009  12:14   
I think the more immediate question is, why do you want to use a published custom form to forward a message? There may be a better approach to what you're trying to accomplish.
  02-Nov-2009  12:48   
The reason is as follow:

I have a custom form that auto-format an email body with different type of selected field by user:

Date, time, checkbox selections and so forth based on live events that are not avail. in data format.

This custom form, basicly make the email for them so its always formated the same.

Once they send it use the following lines:

Function Item_Send()
  Item_Send = False
  Send_Duplicate()
  Item_Close()
End Function

Within my Send_Duplicate() function, i create the email assigning the formated text to Item.HTMLBody. My problem is i don't know how to get to the selected item while in the the custom form code.

 
  02-Nov-2009  12:48   
correction: ..... to the selected item while in the ....

..... to the selected outlook item while in the ...
  02-Nov-2009  12:55   
What exactly do you mean by "the selected Outlook item"?
  02-Nov-2009  13:21   
ok, let me give you a full senario:

I have 20+ operator that must forward items from a "shared" mailbox. These items are located in "new" folder they create upon receptions.

Currently the users must do the following:
-They must select the item they want to forward in outlook
-click forward
-copy a template from a TXT file,
-copy text from a 3rd party application (no way to send querry to it, so must be done manually)
-search for address in a XLS file
-modify the subject line based on other info

All those steps are supported in the Custom form i made, except the forward part.

I can get the form to flash up with that marco above, but i don't know how to get the .HTMLbody value of the original "selected" item from the outlook apps.


Here is an extract of the form's code:

********************************************************

Function Item_Open()
  '********* Set initial Form Value **********
  Item.Getinspector.Height = 690
  Item.Getinspector.Width = 935
End Function

Function Item_Send()
  'Stop the custom form from sending
  Item_Send = False

  'Send a message with no code behind it
  Send_Duplicate()

  'Call the Item_Close Function to close the custom form
  Item_Close()
End Function

Function Item_Close()
  'Left blank for now
End Function

Function Send_Duplicate()

Dim CountRecipients
Dim LoopRecipients
Dim NewRecipient
Dim fso
Dim objAtt
Dim fldTemp
Dim CountAttachments
Dim LoopAttachments

CountRecipients = Item.Recipients.Count
CountAttachments = Item.Attachments.Count

Set sendMail = Application.CreateItem(0)
Set fr_SDA = Item.Getinspector.ModifiedFormPages("Service Release").Controls("fr_SDA")
Set fr_SRScope = Item.Getinspector.ModifiedFormPages("Service Release").Controls("fr_SRScope")

strFrom = ""
strEmailA1 = ""
strEmailA2 = ""
strEmailA3 = ""
(many more times for each address)

Item.SentOnBehalfOfName = strFrom

If fr_SDA.Controls("ck_EmailA1").value = -1 THEN
   ' Add default "TO" address
   Set NewRecipient = .Recipients.add (strEmailA1)
   NewRecipient.type = 1 'TO address
End IF
(many more times for each address)

'Copy EXTRA the recipients
For LoopRecipients = CountRecipients To 1 Step -1
    Set NewRecipient = .Recipients.Add (Item.Recipients(LoopRecipients).Address)
    NewRecipient.Type = Item.Recipients(LoopRecipients).Type
Next

.Recipients.ResolveAll

'Copy the from address
.SentOnBehalfOfName = Item.SentOnBehalfOfName

'Copy the attachments
(removed, no conserned)

'Copy the subject
 .Subject = Item.Subject

strBody = "all my info goes here from different txt box"
    
'Copy the composed body to the Message field of the form
Item.HTMLBody = strBody

'Copy the email message to the NEW email.
.HTMLBody = Item.HTMLBody

'Send the message
.Display


********************************************************


This is an extract but it should clarrify some background info. Now the whole template works just fine, i just can't interface with the item from outlook that is currently selected. (would seem i don't know how, silly me)

 
  02-Nov-2009  13:37   
The ActiveExplorer.Selection collection will give you the item(s) -- note potential plural -- selected in a folder view. But, perhaps instead of the "currently selected" item, you really need the item from which the forward message was created? If so, see http://www.outlookcode.com/codedetail.aspx?id=1714 for a VBA code sample that you should be able to adapt to VBScript.
  02-Nov-2009  13:49   
ok, let me give you a full senario:

I have 20+ operator that must forward items from a "shared" mailbox. These items are located in "new" folder they create upon receptions.

Currently the users must do the following:
-They must select the item they want to forward in outlook
-click forward
-copy a template from a TXT file,
-copy text from a 3rd party application (no way to send querry to it, so must be done manually)
-search for address in a XLS file
-modify the subject line based on other info

All those steps are supported in the Custom form i made, except the forward part.

I can get the form to flash up with that marco above, but i don't know how to get the .HTMLbody value of the original "selected" item from the outlook apps.


Here is an extract of the form's code:

********************************************************

Function Item_Open()
  '********* Set initial Form Value **********
  Item.Getinspector.Height = 690
  Item.Getinspector.Width = 935
End Function

Function Item_Send()
  'Stop the custom form from sending
  Item_Send = False

  'Send a message with no code behind it
  Send_Duplicate()

  'Call the Item_Close Function to close the custom form
  Item_Close()
End Function

Function Item_Close()
  'Left blank for now
End Function

Function Send_Duplicate()

Dim CountRecipients
Dim LoopRecipients
Dim NewRecipient
Dim fso
Dim objAtt
Dim fldTemp
Dim CountAttachments
Dim LoopAttachments

CountRecipients = Item.Recipients.Count
CountAttachments = Item.Attachments.Count

Set sendMail = Application.CreateItem(0)
Set fr_SDA = Item.Getinspector.ModifiedFormPages("Service Release").Controls("fr_SDA")
Set fr_SRScope = Item.Getinspector.ModifiedFormPages("Service Release").Controls("fr_SRScope")

strFrom = ""
strEmailA1 = ""
strEmailA2 = ""
strEmailA3 = ""
(many more times for each address)

Item.SentOnBehalfOfName = strFrom

If fr_SDA.Controls("ck_EmailA1").value = -1 THEN
   ' Add default "TO" address
   Set NewRecipient = .Recipients.add (strEmailA1)
   NewRecipient.type = 1 'TO address
End IF
(many more times for each address)

'Copy EXTRA the recipients
For LoopRecipients = CountRecipients To 1 Step -1
    Set NewRecipient = .Recipients.Add (Item.Recipients(LoopRecipients).Address)
    NewRecipient.Type = Item.Recipients(LoopRecipients).Type
Next

.Recipients.ResolveAll

'Copy the from address
.SentOnBehalfOfName = Item.SentOnBehalfOfName

'Copy the attachments
(removed, no conserned)

'Copy the subject
 .Subject = Item.Subject

strBody = "all my info goes here from different txt box"
    
'Copy the composed body to the Message field of the form
Item.HTMLBody = strBody

'Copy the email message to the NEW email.
.HTMLBody = Item.HTMLBody

'Send the message
.Display


********************************************************


This is an extract but it should clarrify some background info. Now the whole template works just fine, i just can't interface with the item from outlook that is currently selected. (would seem i don't know how, silly me)

 
  02-Nov-2009  13:51   
doh sorry, double post when i refresh the screen
  02-Nov-2009  13:52   
Thanks soo much for your time and efforts. I'll look it up and get back to you.


PO2 Leclerc
    Page [ 1 ]  
Post a new message to this topic.



name        email