+ Reply to Thread
Page 1 of 6 123 ... LastLast
Results 1 to 15 of 82

Thread: outlook 2007 automation

  1. #1
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    outlook 2007 automation

    Thank God I found this forum ...Guys
    I need Help ...Here is the problem I have tried to explain it through the attachment also ..

    Object: Outlook 2007 automation
    Components: Microsoft Outlook 2007 and excel 2007
    Query:
    1/ I want to send e mails to all the names in Column A,and with E mails in Column B:C:D:E .Imported from the outlook contact list.how to import the list into this format from excel?
    2/ The content of the e mail will contain Text along with the account status imported from Excel 2007 to outlook 2007 without losing the table and color (format)
    3/ The format never changes and I want to link it to the contact details in the outlook 2007 address book .
    4/ I also want to add 'Bcc:' and Cc: using the outlook contacts.
    Attached is the Excel Sheet giving a screen shot of the requirement.Please help God Bless
    Attached Files Attached Files
    Last edited by nuttycongo123; 01-27-2011 at 05:56 AM.

  2. #2
    Registered User
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    88

    Re: outlook 2007 automation

    I have not tested this, i use thunderbird not outlook.
    Sub SendEmail()
    
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    
    Application.ScreenUpdating = False
    Range("B1").Select
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
    .To = ActiveCell.Value & ActiveCell.Offset(1, 1)
    .BCC = ActiveCell.Offset(1, 2)
    .Cc = ActiveCell.Offset(1, 3)
    .Subject = "Your Account Status"
    
    .body = "Hi Alis," & NewLine & "This is to update your account status with us." & NewLine & "Todays position is:" & NewLine
    .body = .body & Range("f1:h2").Cells
    .display
    
    'put .send after .display to send the email automatically'
    End With
    
    End Sub
    Last edited by GaidenFocus; 01-26-2011 at 11:33 AM.

  3. #3
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Thanks a ton will check and update ...

  4. #4
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Hey I am gettin :
    Runtime error # 13 type mismatch !! any ideas on this.I am an absolute newbee at VBA

  5. #5
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Couple of things You missed here :
    1/ I want my signature to be on the e mail.
    2/ declaring Newline as a variable .. if I write it as :

    Dim NewLine as Long

    Will that be correct ??
    Chao !!

  6. #6
    Registered User
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    88

    Re: outlook 2007 automation

    try
    Dim NewLine As String

  7. #7
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Still the Same error "Run time Error 13 -Type Mismatch"...any clue

  8. #8
    Registered User
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    88

    Re: outlook 2007 automation

    ill try it when i get home, i have outlook there. my work computer does not. ill see what i can do!

  9. #9
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Quote Originally Posted by GaidenFocus View Post
    ill try it when i get home, i have outlook there. my work computer does not. ill see what i can do!
    @ thankls awaiting your respponse

  10. #10
    Forum Guru
    Join Date
    01-03-2006
    Location
    Taranaki, New Zealand
    MS-Off Ver
    2007 (work & home)
    Posts
    2,242

    Re: outlook 2007 automation

    hi,

    I think you can remove the "Dim Newline as string" & add "vb" to the front of "newline" where it is used (ie "vbnewline"). vbnewline is a known/native vba constant for ascii (?) code number 13, which is a type of line break.

    Edit: what line of code is highlighted if you click debug when the error message pops up? /edit

    hth
    Rob
    Last edited by broro183; 01-29-2011 at 06:11 AM.
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  11. #11
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Quote Originally Posted by broro183 View Post
    hi,

    I think you can remove the "Dim Newline as string" & add "vb" to the front of "newline" where it is used (ie "vbnewline"). vbnewline is a known/native vba constant for ascii (?) code number 13, which is a type of line break.

    Edit: what line of code is highlighted if you click debug when the error message pops up? /edit

    hth
    Rob
    I have new set of queries now .
    1/ Edit Following code.in line with the my uploaded file (attachment )
    2/ How to combine two functions to act as one
    I am posting two procedure and functions which will help ,if corrected of course ,in achieving the desired goal ,.If you can edit /correct /rectify these i will be great full.

    Procedures:


    Sub Send_Row_Or_Rows_2()
    ' Don't forget to copy the function RangetoHTML in the module.
    ' Working in Office 2000-2010
    Dim OutApp As Object
    Dim OutMail As Object
    Dim rng As Range
    Dim Ash As Worksheet
    Dim Cws As Worksheet
    Dim Rcount As Long
    Dim Rnum As Long
    Dim FilterRange As Range
    Dim FieldNum As Integer
    Dim strBody As String
    Dim SigString As String
    Dim Signature As String


    On Error GoTo cleanup

    Set OutApp = CreateObject("Outlook.Application")

    With Application
    .EnableEvents = False
    .ScreenUpdating = False
    End With

    'Set filter sheet, you can also use Sheets("MySheet")
    Set Ash = ActiveSheet

    'Set filter range and filter column (column with e-mail addresses)
    Set FilterRange = Ash.Range("A1:H" & Ash.Rows.Count)
    FieldNum = 2 'Filter column = B because the filter range start in column A

    'Add a worksheet for the unique list and copy the unique list in A1
    Set Cws = Worksheets.Add
    FilterRange.Columns(FieldNum).AdvancedFilter _
    Action:=xlFilterCopy, _
    CopyToRange:=Cws.Range("A1"), _
    CriteriaRange:="", Unique:=True

    'Count of the unique values + the header cell
    Rcount = Application.WorksheetFunction.CountA(Cws.Columns(1))

    'If there are unique values start the loop
    If Rcount >= 2 Then
    For Rnum = 2 To Rcount

    'Filter the FilterRange on the FieldNum column
    FilterRange.AutoFilter Field:=FieldNum, _
    Criteria1:=Cws.Cells(Rnum, 1).Value

    'If the unique value is a mail addres create a mail
    If Cws.Cells(Rnum, 1).Value Like "?*@?*.?*" Then

    With Ash.AutoFilter.Range
    On Error Resume Next
    Set rng = Selection.SpecialCells(xlCellTypeVisible)
    On Error GoTo 0

    If rng Is Nothing Then
    MsgBox "The selection is not a range or the sheet is protected. " & _
    vbNewLine & "Please correct and try again.", vbOKOnly
    Exit Sub
    End If

    With Application
    .EnableEvents = False
    .ScreenUpdating = False


    End With
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
    .To = Cws.Cells(Rnum, 1).Value
    .CC = ""
    .BCC = ""
    .Subject = "Test mail"
    strBody = "<H3><B>Dear Customer</B></H3>" & _
    "Please visit this website to download the new version.<br>" & _
    "Let me know if you have problems.<br>" & _
    "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
    "<br><br><B>Thank you</B>"
    .HTMLBody = strBody & RangetoHTML(rng)
    .Display 'Or use Send
    End With
    On Error GoTo 0


    With Application
    .EnableEvents = True
    .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
    End With

    End If
    Set OutMail = Nothing
    'End If

    'Close AutoFilter
    Ash.AutoFilterMode = False

    Next Rnum
    End If

    cleanup:
    Set OutApp = Nothing
    Application.DisplayAlerts = False
    Cws.Delete
    Application.DisplayAlerts = True

    With Application
    .EnableEvents = True
    .ScreenUpdating = True
    End With
    SigString = "C:\Users\" & Environ("Alok") & "\AppData\Roaming\Microsoft\Signatures\Alok.htm"

    If Dir(SigString) <> "" Then
    'Signature = GetBoiler(SigString)
    Else
    Signature = ""
    End If

    End Sub

    2] Procedure:

    'To use the code that is presented in this section, first create a table on the active sheet with the following columns:

    '* Column A: Names of the people

    '* Column B: E-mail addresses

    '* Column C: yes or no ( if the value is yes, an e-mail message is created)

    'The following subroutine loops through each row on the active sheet and, if there is an e-mail address in column B and Yes in column C, an e-mail message for each person listed in column A is created that has a reminder



    Sub Create_Mail_From_List()
    ' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range

    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")

    On Error GoTo cleanup
    For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" And _
    LCase(Cells(cell.Row, "C").Value) = "yes" Then

    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
    .To = cell.Value
    .Subject = "Reminder"
    .Body = "Dear " & Cells(cell.Row, "A").Value _
    & vbNewLine & vbNewLine & _
    "Please contact us to discuss bringing " & _
    "your account up to date"
    'You can also add files like this:
    '.Attachments.Add ("C:\test.txt")
    .Send 'Or use Display.
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    End If
    Next cell

    cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
    End Sub


    3// Functions:
    Option Explicit

    Function RangetoHTML(rng As Range)
    ' Changed by Ron de Bruin 28-Oct-2006
    ' Working in Office 2000-2010
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook
    'Dim GetBoiler 'ByVal_
    'Dim sFile As String 'As String

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
    .Cells(1).PasteSpecial Paste:=8
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).Select
    Application.CutCopyMode = False
    On Error Resume Next
    .DrawingObjects.Visible = True
    .DrawingObjects.Delete
    On Error GoTo 0
    End With

    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
    SourceType:=xlSourceRange, _
    Filename:=TempFile, _
    Sheet:=TempWB.Sheets(1).Name, _
    Source:=TempWB.Sheets(1).UsedRange.Address, _
    HtmlType:=xlHtmlStatic)
    .Publish (True)
    End With

    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.readall
    'Set fso = CreateObject("Scripting.FileSystemObject")
    'Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    'GetBoiler = ts.readall
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
    "align=left x:publishsource=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile
    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
    End Function
    .................................................................................................... ...........................

    4] Function:
    Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
    End Function

    PS:
    I think I will be able to get the desired result these codes are modified/corrected in a proper way ..Awaiting Reply ..
    Chao!!

  12. #12
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Hey Thanks for replying ..I appreciate ..I am still gettin the same error:

  13. #13
    Forum Guru
    Join Date
    01-03-2006
    Location
    Taranaki, New Zealand
    MS-Off Ver
    2007 (work & home)
    Posts
    2,242

    Re: outlook 2007 automation

    hi nuttycongo123,

    Can you please edit your last post to...?
    1) use code tags around your code.
    2) supply a link to the specific webpage of Ron DeBruin's that you copied the code from.
    3) upload an attachment with what you have tried so far.
    4) include more specific questions & details about the exact problems you are having.

    Based on the attachment in the first post I have some suggestions:
    - remove Merged Cells from your spreadsheet because they can cause all sorts of problems. A similar visual impact can be achieved by selecting the group of unmerged cells, pressing [ctrl + 1], choosing the Alignment tab and changing the dropdown relating to Horizontal to "center across selection".
    - move the code from the worksheet module into a normal module.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  14. #14
    Forum Guru
    Join Date
    01-03-2006
    Location
    Taranaki, New Zealand
    MS-Off Ver
    2007 (work & home)
    Posts
    2,242

    Re: outlook 2007 automation

    hi,

    I'd love to help, once you've edited the earlier post as requested, but some more detail would be useful ie
    What line of code is highlighted if you click debug when the error message pops up?
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  15. #15
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: outlook 2007 automation

    Hey Rob,
    I am getting the same error .Lines are:
    Set OutApp = CreateObject("Outlook.Application")
    .Body = "Hi Alis," & "vbNewline" & "This is to update your account status with us." & "vbNewline" & "Todays position is:" & 'vbNewline"

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0