將格式化的項目符號導出到Excel TextBox的電子郵件中

[英]Export formatted bullets to an email from Excel TextBox


I've been working on a spread sheet to allow my team to manage our workload more effectively, whilst the business is developing a new tool. Anyway, what the sheet does is inject information, then at the click of a button, it populates an OFT email template so that the info can be sent out.

我一直在制作電子表格,以便我的團隊能夠更有效地管理我們的工作量,同時業務正在開發一種新工具。無論如何,工作表所做的是注入信息,然后在點擊按鈕時,它會填充OFT電子郵件模板,以便可以發送信息。

Problem is, we rely heavily on bullet lists for our emails, and I'm really struggling to find a way of adding bullets effectively from an ActiveX Textbox.

問題是,我們在很大程度上依賴於電子郵件的子彈列表,我真的很難找到一種從ActiveX文本框中有效添加項目符號的方法。

At the moment, I have a button which adds the follow to a text box:

目前,我有一個按鈕,可以在文本框中添加以下內容:

[bullets] * Bullet 1 * Bullet 2 * Bullet 3 [/bullets]

[子彈] *子彈1 *子彈2 *子彈3 [/子彈]

I then have Replace statements that look for strings and it replaces them with the appropriate HTML tags. Here's the code:

然后我有替換查找字符串的語句,並用適當的HTML標記替換它們。這是代碼:

' Add HTML formatting to text updates so it displays correctly in the email.
LatestUpdate.Text = Replace(LatestUpdate, "[bullets]", "<ul>")
LatestUpdate.Text = Replace(LatestUpdate, "[/bullets]", "</ul>")
LatestUpdate.Text = Replace(LatestUpdate, "* ", "<li>")
LatestUpdate.Text = Replace(LatestUpdate, vbCrLf, "<br>")

The problem I'm having, is that non-technical people are using this document, so I would really like to have it in such a way were they don't have to look at the markup, but can simple add bullets straight from the textbox.

我遇到的問題是,非技術人員正在使用這個文檔,所以我真的希望以這種方式擁有它,如果他們不必看標記,但可以簡單地直接添加子彈文本框。

I was originally thinking about replacing "* " with "< li >" however, that doesn't add the correct < ul > tags, so it's not actually a bullet list within the email.

我原本打算用“

  • ”替換“*”但是,它沒有添加正確的
      標簽,所以它實際上並不是電子郵件中的子彈列表。

  • “替換”*“但是,它沒有添加正確的標簽,所以它實際上並不是電子郵件中的子彈列表。
  • Can anyone help in simplifying this process for the end users please? I'm really stuck.

    任何人都可以幫助最終用戶簡化此過程嗎?我真的被卡住了。

    The holy grail would be to enable rich text formatting on the textbox, but I don't believe that's possible from all the research I've done?

    聖杯將在文本框上啟用豐富的文本格式,但我不相信我所做的所有研究都可以實現這一點?

    TIA.

    TIA。

    1 个解决方案

    #1


    0  

    Based on your last comment, what you are looking for is not just a bullet point in your textbox but indentation as well. So here is an attempt at it:

    根據您的上一條評論,您所尋找的不僅僅是文本框中的項目符號,還有縮進項。所以這是一個嘗試:

    First add the below in your <textbox>_KeyUp function:

    首先在 _KeyUp函數中添加以下內容:

    Private Sub txtBulletPoints_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
        Dim STRING_LENGTH As Long: STRING_LENGTH = 49
        Dim aLine() As String
        Dim aLineSpace() As String
        Dim iC As Integer
        Dim sText As String
        Dim bUpdate As Boolean
    
        ' Only do this if there is a string to work with
        If Len(Me.txtBulletPoints.Text) > 0 Then
    
            ' Set initial values
            aLine = Split(Me.txtBulletPoints.Text, vbCrLf)
            bUpdate = False
    
            ' First lets indent the last line if we need to
            If Left(aLine(UBound(aLine)), 2) = "- " Then
                For iC = LBound(aLine) To UBound(aLine)
                    If iC = UBound(aLine) Then
                        sText = sText & vbTab & aLine(iC)
                    Else
                        sText = sText & aLine(iC) & vbCrLf
                    End If
                Next
    
                Me.txtBulletPoints.Text = sText
    
            End If
    
            ' Now the tricky bit. Check if we have reached the end of the
            ' line so that we can indent the text into the next line
            If (Len(aLine(UBound(aLine))) >= STRING_LENGTH) And (InStr(1, aLine(UBound(aLine)), vbTab) = 1) Then
                For iC = LBound(aLine) To UBound(aLine)
                    If iC = UBound(aLine) Then
                        aLineSpace = Split(aLine(iC), " ")
    
                        ' As we have to indent the last bullet point line, call the finction to do that
                        sText = sText & SetIndentsInString(aLine(iC), STRING_LENGTH)
    
                    Else
                        sText = sText & aLine(iC) & vbCrLf
                    End If
                Next
    
                Me.txtBulletPoints.Text = sText
    
            End If
    
        End If
    
    End Sub
    

    Now add the below UDF where your form code is (essentially at the same place where your <textbox>_KeyUp function is):

    現在在表單代碼所在的位置添加以下UDF(基本上與 _KeyUp函數所在的位置相同):

    Function SetIndentsInString(ByVal sString As String, ByVal iIndentLen As Long) As String
        Dim iC As Long
        Dim iLastTab As Long: iLastTab = 0
        Dim aSpace() As String
        Dim aTab() As String
        Dim sCurString As String
    
        ' Check if the string is the same as what it was last
        ' time (sLastString is a private module variable initialised
        ' to "" when the form is activated)
        If Replace(sString, vbTab, "") = Replace(sLastString, vbTab, "") Then
            ' Its the same string so lets return it as is
            SetIndentsInString = sString
        Else
            ' Its not the same string so set initial values
            sLastString = sString
            SetIndentsInString = ""
    
            ' Loop to see how many lines we have based on number of TABs in the string
            Do While InStr(iLastTab + 1, sString, vbTab) > 0
                iLastTab = iLastTab + InStr(iLastTab + 1, sString, vbTab)
            Loop
    
            ' If there is only 1 TAB, simply indent the line
            If iLastTab = 1 Then
                aSpace = Split(sString, " ")
                SetIndentsInString = Mid(sString, 1, Len(sString) - Len(aSpace(UBound(aSpace)))) & vbTab & "  " & aSpace(UBound(aSpace))
            Else
    
                ' More then 1 TAB.. damn!. Ok well lets work it
                aTab = Split(sString, vbTab)
                sCurString = aTab(UBound(aTab))
    
                ' Check if the last line of our bullet point has more characters then allowed in a line
                If Len(sCurString) >= iIndentLen Then
    
                    ' It does. Now loop through all the lines in our bullet point and set the last character in a new line with indent
                    aSpace = Split(sCurString, " ")
                    For iC = LBound(aTab) To UBound(aTab)
                        If iC = UBound(aTab) Then
                            SetIndentsInString = SetIndentsInString & Mid(sCurString, 1, Len(sCurString) - Len(aSpace(UBound(aSpace)))) & vbTab & "  " & aSpace(UBound(aSpace))
                        Else
                            SetIndentsInString = SetIndentsInString & aTab(iC) & vbTab
                        End If
                    Next
    
                Else
    
                    ' It doesnt. Loop through and send the string back
                    SetIndentsInString = sString
    
                End If
    
            End If
    
        End If
    
    End Function
    

    Now in the same module, make the following declaration at the top:

    現在在同一個模塊中,在頂部進行以下聲明:

    Private sLastString As String
    

    Essentially the above will act like a bullet point as it would be in a Rich Text box. Things to remember is that you will have to set STRING_LENGTH to the number of characters your textbox will take in a given bullet point line (you will have to play around with that). Below is a screen print of how it worked for me
    enter image description here

    從本質上講,上面的內容就像一個子彈點,就像在富文本框中一樣。要記住的是,您必須將STRING_LENGTH設置為文本框在給定項目符號線中所占用的字符數(您必須使用它)。下面是它如何為我工作的絲網印刷


    注意!

    本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/09/21/30ee0be9bdc976104205ad4f7d60463f.html



     
      © 2014-2022 ITdaan.com 联系我们: