Posts Tagged Hello

Email Excel Spreadsheet as Email Body Issues

Hello all. I had a production manager wanting an excel spreadsheet mailed as the body of the email. As some of you know the code generated by excel to produce the email is pretty crazy. But as a result, it showed up fine in Outlook and Android but it did not show the gridlines on the spreadsheet. So this code is based on the excellent work by Ron DeBruin over at http://www.rondebruin.nl/win/s1/outlook/bmail3.htm . I did a replacement for the HTML Range in this manner and the grid lines did appear. And the manager was happy.

Sub Mail_Selection_Range_Outlook_Body()
‘For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
‘Don’t forget to copy the function RangetoHTML in the module.
‘Working in Excel 2000-2016
    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object
‘MsgBox Cells(5, 9).Value
    Set rng = Nothing
    On Error Resume Next
    ‘Only the visible cells in the selection
    Set rng = Selection.SpecialCells(xlCellTypeVisible)
    ‘You can also use a fixed range if you want
    ‘Set rng = Sheets(“YourSheet”).Range(“D4:D12”).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
        .BodyFormat = olFormatHTML
        .To = “you@you.com”       
           
               
       
         .CC = “”
        .BCC = “”
        .Subject = “Testing Purchase Order Email To Steve”
        .HTMLBody = RangetoHTML(rng)
        Replace .HTMLBody, “border-left:none”, “border-left:solid;border-width: 1px;border-color:black”
        Replace .HTMLBody, “border-right:none”, “border-right:solid;border-width: 1px;border-color:black”
        Replace .HTMLBody, “border-bottom:none”, “border-bottom:solid;border-width: 1px;border-color:black”
        Replace .HTMLBody, “border-top:none”, “border-bottom:solid;border-width: 1px;border-color:black”
        .Send
         ‘or use .Display
    End With
    On Error GoTo 0

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

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a comment

Fluent C# Review : Chapter Two

I am reviewing an advanced copy of the book Fluent C# by noted .NET author Rebecca Riordan.

My focus today will be on Chapter Two. Chapter Two gets into some of the nuts and bolts of the .NET Framework and writes the initial “Hello World” application that these beginner books almost always do. They begin by putting up a very nice illustration of how .NET works. Truly I have not seen it explained in such a way before!

image

They give you a little quiz on what you picked up.

Then there is an explanation of why the .NET Framework is a better way to go than say a Visual Basic 6 way of thinking. I am not sure that to a beginner programmer they understand or need to know any of this. But they certainly make good points. Being an old VB6 and VBA programmer myself I certainly could appreciate what was said.

Then they proceed into building the first application. But there is a little twist. Riordan chooses to not even bother with winforms and instead chooses to plow right into a Windows Presentation Foundation (WPF) application. At first the choice seemed odd to me. But as I considered it this makes sense. WPF is the future. Winforms is dying. It’s a sad truth but it is what it is.

Riordan walks you through the process of creating a WPF application in Visual Studio 2010 while beautifully illustrating how to do that task.

image

Then the first example of modifying a property in the WPF gui is introduced. Really it is quite well done. The appropriate message box appears saying “hello world!” is displayed. She tells the user to take a break and congratulates them on their first application. She then displays and explains the code editor in the same easy going manner. Another note that often goes on through out this book she often gives the novice programmer fun little facts to digest, so as to have fun while learning. Imagine that! C# learning being made fun!

We will be covering Chapter Three in the next entry where the Visual Studio interface will be reviewed in more detail.

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

1 Comment