Results 1 to 10 of 380

Thread: Appendix Thread. ( Codes for other Threads, etc.) Event Coding Drpdown Data validation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Function Code for solution to this Thread and Post
    http://www.excelfox.com/forum/showth...0518#post10518




    HTML For CDO.Message.HTMLBody in VBA Emails sending

    Linked in my Binding Function, MyLenghtyString LBF_MLS
    In support of this Thread:
    http://www.excelfox.com/forum/showth...kbooks-at-once

    HTM / HTML is a very typical electronic message language recognised by most software devices associated with Email and similar.
    In two ways considered in this Thread , http://www.excelfox.com/forum/showth...0512#post10512 , the main Message Text body to be sent in an Email can be supplied as a single HTML code string.

    One convenient way to supply this is with a simple Word.doc file which can simply saved with a htm file extension
    Word doc to htm.JPG : https://imgur.com/vhRE9CC

    By opening this with a simple text editor, the actual text along with much more htm code detail can be revealed
    LastBitOfProMessage htm.JPG : https://imgur.com/mT6l40I
    LastBitOfProMessage htm 2.JPG : https://imgur.com/s0U8419

    This is the actual text required to be given after the an Email data filling code line like:
    _ .HTMLBody =

    The actual file held anywhere will likely include all sorts of computery stuff in addition to that text.
    We can get at just the text in several ways.
    A typical way in VBA is to make use of one of a number of Object Orientated stuff held in the Visual Basic FileSystemObject Object. This is in turn part of the Bundle in the available to application programs (such as Excel VBA) Library, Microsoft Scripting Runtime

    The way this works is as follows.
    For a given file, a large object can be made within the Microsoft Scripting Runtime Library Class type Module like Library, ** Polymorphically speaking.
    The Microsoft Scripting Runtime FileSystemObject Object GetFile method returns this object requiring only its full file path in order to “Get at it” . ( The returned object is pseudo in the streaming runtime instant direct compiling linking .Net technology held as a running link, ( indeed by assigning the object to, or using in an environment of, String will itself return that arguments string reference ) )
    **:From Microsoft documentation: Visual Basic provides polymorphism through multiple ActiveX interfaces. In the Component Object Model (COM) that forms the infrastructure of the ActiveX specification, multiple interfaces allow systems of software components to evolve and break existing code.
    In this sense interface is a set of related properties and methods. Much of the ActiveX specification is concerned with implementing standard interfaces to obtain system services or to provide malfunctionality to other programs.
    The actual processes involved are in the meantime so messed up that it is a wonder that anything still works, and I doubt it will be long before nothing does.
    The large FileObject in the Microsoft Scripting Runtime Library Class type Module like Library has information , amongst other things of neighbouring things , and as is typical in this mixed up messed up process , a short tem path or highway is made, and more often than not a “text stream object”, something like a continuous stream of data or like a highways going around in circles, and this will only be of a runtime existence, or at any rate should.. during this lifetime it can be “read”. I guess for any file of any type data within it will be recognised as such and can be handled in this simple text stream way.

    The original coding goes quite a way back and does not really fit in Object Orientated Visual basic hierarchical structure of the original implementation of File I/O in Visual Basic. But it does at lest work well in getting at text stream string things which we are interested in

    The available methods and the such reflect all the above…
    -…So code will have a string getting section that..
    1(i) makes available the Library of stuff, objects, Methods etc.
    1(ii) makes the big File Object
    1(iii) sets up the data “stream highway”
    1(iv) pulls in the data, in our case into a simple string variable


    _.____
    I have decided for my requirement to use a “Function” for this, not just to house tidily the above steps, but also as I may add some additional bits from time to time too the main inner body string for my Email message, which the main function of this all is to produce.
    To recap on the Function idea here ( http://www.excelfox.com/forum/showth...blem#post10503 )

    In end effect I want a String. In fact in the main code in which this should be embedded has this as a variable
    Pseudo, Linked in my Binding Function, ObjectLinkedEbeded Stuff
    In place of an actual static linked variable_...
    Dim MyLenghtyString As String
    _ Let MyLenghtyString = “static linked at pseudo Compile String”

    _.. I have
    Function MyLenghyString(Export) As String
    _ Pall MyLenghyString()_Import
    _.. or Let MyLenghtyString = “direct linked runny runable library”


    The end result is that in my code I will have simply pulling of

    _ .HTMLBody = MyLengthyStreaming


    Function Code description:
    Rem 1
    This uses the File System Object way discussed above to finally produce a long text string in variable _ MyLengthyStreaming _ This string probably has a of unnecessary stuff as well as the required part of the HTML code, but appears to be able to be handled and manipulated as if it were just the required part. Presumably the rest is ignored by things such as internet browsers

    Rem 2
    This allows for some extra simple string data to be added. If you are not familiar with HTML code then you can easily get the required string from text to HTML converters of which there are many freely available in internet
    Note: If you have any in your required HTML string, then you will need to replace them in the given string in the VBA code with “”
    http://www.excelfox.com/forum/showth...rmat#post10448






    ' https://support.microsoft.com/en-in/kb/186118
    https://www.youtube.com/watch?v=nj8mU3ecwsM
    https://www.youtube.com/watch?v=f8s-jY9y220&t=1813s




    Note: ' path in code must be changed to reflect where you save .htm file
    Pubic Function MyLengthyStreaming() As String
    Code:
    Public Function MyLengthyStreaming() As String
    Rem 1 Make a long string from a Microsoft Word doc
    '1(i) makes available the Library of stuff, objects, Methods etc.
    Dim Fso As Object: Set Fso = CreateObject("Scripting.FileSystemObject")
    '1(ii) makes the big File Object                       " Full path and file name of Word doc saved as .htm       "
    Dim FileObject As Object: Set FileObject = Fso.GetFile("G:\ALERMK2014Marz2016\NeueBlancoAb27.01.2014\AbJan2016\ProMessage.htm"): Debug.Print FileObject  ' path in code must be changed to reflect where you save it
    '1(iii) sets up the data  "stream highway"
    Dim Textreme As Object:  Set Textreme = FileObject.OpenAsTextStream(iomode:=1, Format:=-2)        '   reading only, Opens using system default            https://msdn.microsoft.com/en-us/library/aa265341(v=vs.60).aspx
    '1(iv) pulls in the data, in our case into a simple string variable
     Let MyLengthyStreaming = Textreme.ReadAll         '        Let MyLengthyStreaming = Replace(MyLengthyStreaming, "align=center x:publishsource=", "align=left x:publishsource=")
     Textreme.Close
     Set Textreme = Nothing
     Set Fso = Nothing
    Rem 2 possible additions to MyLengthyStreaming
    HTML Code:
    Rem 2
     Let MyLengthyStreaming = "<p><span style=""color: #ff00ff;"">Start=========== " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ------------------------------------</span></p>" & MyLengthyStreaming & "<p><span style=""color: #ff00ff;"">-- " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ==End, Sent from Doc.AElstein Mail ======</span></p>"
    End Function


    MyLengthyStreaming = "<p><span style=""color: #ff00ff;"">Start=========== " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ------------------------------------</span></p>" & MyLengthyStreaming & "<p><span style=""color: #ff00ff;"">-- " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ==End, Sent from Doc.AElstein Mail ======</span></p>"
    MyLengthyStreaming = "[color=Black]<[/color]p[color=Black]>[/color][color=Black]<[/color]span style=""color: #ff00ff;""[color=Black]>[/color]Start=========== " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ------------------------------------[color=Black]<[/color]/span[color=Black]>[/color][color=Black]<[/color]/p[color=Black]>[/color]" & MyLengthyStreaming & "[color=Black]<[/color]p[color=Black]>[/color][color=Black]<[/color]span style=""color: #ff00ff;""[color=Black]>[/color]-- " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ==End, Sent from Doc.AElstein Mail ======[color=Black]<[/color]/span[color=Black]>[/color][color=Black]<[/color]/p[color=Black]>[/color]"

    Code:
    Public Function MyLengthyStreaming() As String
    Rem 1 Make a long string from a Microsoft Word doc
    '1(i) makes available the Library of stuff, objects, Methods etc.
    Dim Fso As Object: Set Fso = CreateObject("Scripting.FileSystemObject")
    '1(ii) makes the big File Object                       " Full path and file name of Word doc saved as .htm       "
    Dim FileObject As Object: Set FileObject = Fso.GetFile("G:\ALERMK2014Marz2016\NeueBlancoAb27.01.2014\AbJan2016\ProMessage.htm"): Debug.Print FileObject
    '1(iii) sets up the data  "stream highway"
    Dim Textreme As Object:  Set Textreme = FileObject.OpenAsTextStream(iomode:=1, Format:=-2)        '   reading only, Opens using system default            https://msdn.microsoft.com/en-us/library/aa265341(v=vs.60).aspx
    '1(iv) pulls in the data, in our case into a simple string variable
     Let MyLengthyStreaming = Textreme.ReadAll         '        Let MyLengthyStreaming = Replace(MyLengthyStreaming, "align=center x:publishsource=", "align=left x:publishsource=")
     Textreme.Close
     Set Textreme = Nothing
     Set Fso = Nothing
    Rem 2 possible additions to MyLengthyStreaming
     Let MyLengthyStreaming = "<p><span style=""color: #ff00ff;"">Start=========== " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ------------------------------------</span></p>" & MyLengthyStreaming & "<p><span style=""color: #ff00ff;"">-- " & Format(Now(), "DD MMMM YYYY") & " " & Now() & " ==End, Sent from Doc.AElstein Mail ======</span></p>"
    End Function

    Results Example:

    Used htm Word File.JPG : https://imgur.com/mwihFBT
    "ProMessage.htm" ( Saved from Word as .htm ) : https://app.box.com/s/cbtodk5srg76a5lowfemrdvei91mfmdq
    Attachment 1969

    Recieved Email gmail.jpg : https://imgur.com/x0NybLa :
    Code:
       '.To = "Doc.AElstein@t-online.de"
       .To = "excelvbaexp@gmail.com"
    Attachment 1972


    Recieved EMail Telekom : https://imgur.com/wqPJSCt
    Recieved EMail Telekom 2.JPG : https://imgur.com/o5mRkak
    Code:
       .To = "Doc.AElstein@t-online.de"
       '.To = "excelvbaexp@gmail.com"
    Attachment 1970Attachment 1971








    _.________________________________________________ ____________________________

    Uploaded file had to be done as .docx to get it to upload at excelfox ( .htm were not permitted to be uploaded )
    To use in code it must be resaved as .html ( ' and path in code must be changed to reflect where you save it )
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Replies: 189
    Last Post: 02-06-2025, 02:53 PM
  2. Replies: 293
    Last Post: 09-24-2020, 01:53 AM
  3. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  4. Restrict data within the Cell (Data Validation)
    By dritan0478 in forum Excel Help
    Replies: 1
    Last Post: 07-27-2017, 09:03 PM

Posting Permissions

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