Blog - Title

April, 2009

Brijs Blogging... Looking Beyond the Obvious

  • Brijs Blogging... Looking Beyond the Obvious

    How to send Excel contents as PDF attachment with the email using CDOSYS


    One of my customer would like to send Excel 2007 worksheet contents as email using CDOSYS. We are facing issues regarding formatting of the contents in the resultant emails on the different email clients. Then we decided to send contents as PDF attachment to avoid such issues.

    Here is the sample code VBA snippet used:

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

    Sub SendMail()
    Dim filepath As String
    filepath = "\\server\test\Excel 2007 Chart.pdf" 'TODO:change filepath for the temp pdf file
     'Exporting range of the excel contents which need to sent out
        Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            filepath, _
            Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
     'Setting up CDOSYS configuration to send out the email 
    Set iMsg = CreateObject("CDO.Message")
        Set iConf = CreateObject("CDO.Configuration")
        Set Flds = iConf.Fields
        With Flds
            .Item("") = 2 'send via port
            .Item("") = "ServerName" 'TODO:update the SMTP server name here
            .Item("") = 25
        End With
        With iMsg
            Set .Configuration = iConf
            .From = "" 'TODO:change email address here
            .To = "" 'TODO:change email address here
            .Subject = "Test message with PDF Attachment"
            .HTMLBody = "Please find the attache excel pdf contents report"
            .AddAttachment (filepath)
        End With
        Set iMsg = Nothing
        Set iConf = Nothing
    End Sub

    Hope this helps.


    Please feel free to write me if you have question related to Microsoft Messaging APIs.

  • Brijs Blogging... Looking Beyond the Obvious

    How to do FindFolder and MoveItem Operations of Exchange Web Services using


    In continuations of my previous post How to do FindItem and GetItem Operations of Exchange Web Services using ; Here is the Exchange Web Services sample in to perform following task:

    • FindFolder(How to perform FindFolder Operation to get FolderId of specific folder for the root of the mailbox)
    • MoveItem (How to perform MoveItem Operation to move an item to the another folder within the mailbox)

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. 

    Private Sub cmdMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMove.Click
                If lstMails.SelectedItems.Count = 1 Then
                    Dim itemID As New ItemIdType
                    itemID.Id = lstMails.SelectedItems(0).SubItems(3).Text
                    'Find the folderId to which we want to move item
                    Dim parentFolder As New DistinguishedFolderIdType
                    parentFolder.Id = DistinguishedFolderIdNameType.root
                    Dim tfTargetFolder As New FolderIdType
                    'Change the name of the folder we are searching for FolderID
                    tfTargetFolder = FindFolder(ServiceBinding, parentFolder, "Test")
                    Dim newItemID As New ItemIdType
                    'Move am Item based on ItemId and FolderID
                    newItemID = MoveItemtoTest(ServiceBinding, itemID.Id, tfTargetFolder)
                    Dim strId As String
                    strId = "New ItemID " + newItemID.Id.ToString
                    MessageBox.Show(strId, "Item Moved", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    MessageBox.Show("Please select a item in list to move", "Item to Move", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            Catch ex As Exception
            End Try
        End Sub
    Public Shared Function FindFolder(ByVal serviceBinding As ExchangeServiceBinding, ByVal fiFolderID As DistinguishedFolderIdType, ByVal fnFldName As String) As FolderIdType
            Dim rvFolderID As New FolderIdType
            ' Create the request and specify the travesal type
            Dim findFolderRequest As FindFolderType = New FindFolderType()
            findFolderRequest.Traversal = FolderQueryTraversalType.Deep
            ' Define the properties returned in the response
            Dim responseShape As FolderResponseShapeType = New FolderResponseShapeType()
            responseShape.BaseShape = DefaultShapeNamesType.Default
            findFolderRequest.FolderShape = responseShape
            ' Identify which folders to search
            Dim folderIDArray() As DistinguishedFolderIdType = New DistinguishedFolderIdType(1) {}
            folderIDArray(0) = New DistinguishedFolderIdType()
            folderIDArray(0).Id = fiFolderID.Id
            'Add Restriction for DisplayName
            Dim ffRestriction As New RestrictionType
            Dim ieToType As New IsEqualToType
            Dim diDisplayName As New PathToUnindexedFieldType
            diDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName
            Dim ciConstantType As New FieldURIOrConstantType
            Dim cvConstantValueType As New ConstantValueType
            cvConstantValueType.Value = fnFldName
            ciConstantType.Item = cvConstantValueType
            ieToType.Item = diDisplayName
            ieToType.FieldURIOrConstant = ciConstantType
            ffRestriction.Item = ieToType
            findFolderRequest.Restriction = ffRestriction
            ' Add the folders to search to the request
            findFolderRequest.ParentFolderIds = folderIDArray
                ' Send the request and get the response
                Dim findFolderResponse As FindFolderResponseType = serviceBinding.FindFolder(findFolderRequest)
                ' Get the response messages
                If findFolderResponse.ResponseMessages.Items(0).ResponseClass = ResponseClassType.Error Then
                    MessageBox.Show("Error Occured")
                    Return Nothing
                    Dim rmta() As ResponseMessageType = findFolderResponse.ResponseMessages.Items
                    Dim rmt As ResponseMessageType
                    For Each rmt In rmta
                        ' Cast to the correct response message type
                        Dim ffResponse As FindFolderResponseMessageType = rmt
                        Dim fFoundFolder As FolderType
                        For Each fFoundFolder In ffResponse.RootFolder.Folders
                            rvFolderID = fFoundFolder.FolderId
                    'Return the FolderID of the last folder found
                    Return (rvFolderID)
                End If
            Catch e As Exception
                Return Nothing
            End Try
        End Function
    Public Shared Function MoveItemtoTest(ByVal serviceBinding As ExchangeServiceBinding, ByVal itemID As String, ByVal trgfldID As FolderIdType) As ItemIdType
            'Setup FolderId and ItemId to be passed to MoveItem
            Dim tfTargetFolder As TargetFolderIdType = New TargetFolderIdType()
            tfTargetFolder.Item = trgfldID
            Dim iiItemId As ItemIdType = New ItemIdType()
            iiItemId.Id = itemID
            'Create request to move Item and specify properties
            Dim miMoveItemRequest As MoveItemType = New MoveItemType()
            miMoveItemRequest.ItemIds = New ItemIdType(1) {}
            miMoveItemRequest.ItemIds(0) = iiItemId
            miMoveItemRequest.ToFolderId = tfTargetFolder
            Dim nID As New ItemIdType
                ' Send the request and get the response
                Dim miResponse As MoveItemResponseType = serviceBinding.MoveItem(miMoveItemRequest)
                If miResponse.ResponseMessages.Items(0).ResponseClass = ResponseClassType.Error Then
                    MessageBox.Show("Error Occured")
                    Return Nothing
                    Dim iirmt As ItemInfoResponseMessageType = miResponse.ResponseMessages.Items(0)
                    If iirmt.Items.Items.Length > 0 Then
                        'Get updated ItemId from the Response Message
                        nID = iirmt.Items.Items(0).ItemId
                        MessageBox.Show("Item Moved")
                        'Return updated ItemID
                        Return nID
                        Return Nothing
                    End If
                End If
            Catch e As Exception
                Return Nothing
            End Try
        End Function

    We can refer to the following articles related to the EWS:

    While we can workout more with Exchange Web Service auto generated proxies but don’t forget to have look at Microsoft Exchange Web Services (EWS) Managed API 1.0 to do stuff with less sweat. :)

  • Brijs Blogging... Looking Beyond the Obvious

    Download for Office 2007 SP2 is available now


    Office 2007 SP2 is available for download

    The 2007 Microsoft Office Suite Service Pack 2 (SP2) provides customers with the latest updates to the 2007 Office suite (the products that are affected by this update are listed below). This download includes two types of fixes:

    • Previously unreleased fixes that were made specifically for this service pack.
      • In addition to general product fixes, this includes improvements in stability, performance, and security.
      • You can find out more information in Knowledge Base Article 953195, where product-specific changes are described.
    • All of the Public Updates, Security Updates, Cumulative Updates, and Hotfixes released through February 2009.

    Before installing this service pack, you are strongly encouraged to read 953195, which describes some big improvements introduced by SP2, and also calls out some important information that you should be aware of before installing.

    For the Outlook 2007 Specific changes in SP2 please refer to the Outlook 2007 improvements in the 2007 Office suite Service Pack 2 article.

    You can also download a workbook that contains a list of issues that are fixed by this service pack from the link mentioned below:

    Download the 2007 Office Service Pack 2 Changes.xlsx package

    Please let us know if you face any Outlook development related issues after upgrading to Office 2007 SP2.

  • Brijs Blogging... Looking Beyond the Obvious

    FYI: Microsoft Unveils Exchange 2010 with Public Beta


    I am exited to share that the public beta of Microsoft Exchange Server 2010 is now available. Exchange 2010 is the first server in a new generation of Microsoft server technology designed and developed to work on-premises and as an online service, and introduces a new integrated e-mail archive and features to reduce costs and improve the user experience.

    For more details visit @ Exchange 2010 or Exchange Team Blog and don’t forget to have glance at new Exchange 2010 features and functionality in action.

  • Brijs Blogging... Looking Beyond the Obvious

    Unable to use Outlook Custom form with MSFlexGrid control


    One of our customer reported that they are not able to use Outlook Custom form with MSFlxGrd control after recent security update installation.

    When they try to open or design the form they are getting “To help prevent malicious code from running, one or more objects in this form were not loaded. For more information, contact your administrator” error message.


    This all started happening because of the security update that released in February 2009, KB960715 (Update Rollup for ActiveX Kill Bits),

    The challenge we face with the KB960715 update is that it kill-bitted certain commonly used VB controls including MSFlxGrd control.

    However, there is remedy to this problem. Since these are Visual Basic Controls, a VB cumulative update released in December 2008 did have new controls that replaced the kill-bitted controls.

    For a list of all the controls that were updated with this roll-up see, KB957924.

    In order to get a hold of these controls, you would need to have at least one development machine where you have the Visual Basic 6 IDE installed. You should then install the following updates on that machine:

    This will update your system with the new controls and to resolve the issue we need to register and use newer version of MSFlxGrd.ocx (file version control.

    Please read the detail findings from The IE Support Team @ Shahinur BIG THANKS for the great work… which make life easier for me and others.

  • Brijs Blogging... Looking Beyond the Obvious

    FYI: Test your VBA coding skills and win!

    Here is a news for you… MSDN® is sponsoring a coding contest for Office 2007, named OfficePalooza! This international contest will run for two weeks beginning April 20, 2009, and features ten fun Visual Basic of Applications™ (VBA) coding challenges in the form of puzzles and games. Each entrant will earn a chance to win one of hundreds of available prizes, determined by a random drawing at the end of the contest.

    In conjunction with this contest, an Advanced Business User theme will run on Microsoft Office Online from mid-April to mid-May, and will showcase the automation and extensibility aspects of Office 2007 through macros, custom VBA coding, the Fluent UI, and Office Open XML.  This collaborative effort will also highlight existing and newly-created content on the MSDN Microsoft Office Developer Center.

    “One important goal of this outreach effort is to familiarize the advanced business user with the incredible depth, breadth, and variety of content that can help them expand their knowledge and skills.” notes Eric White, Technical Evangelist in the Developer and Platform Evangelism Group for Microsoft Office. “There are articles, multimedia demos and webcasts, advice columns, forums, downloads and more. This content is designed to increase the user’s efficiency and effectiveness with Office 2007, and covers a spectrum including the beginner macro creator, the experienced VBA coder, and even the professional software developer. This effort also highlights some of the new capabilities and features of the 2007 Office System, such as the Office Fluent UI and the Office Open XML file formats.”

    Happy Coding!

  • Page 1 of 1 (7 items)