+ Reply to Thread
Results 1 to 10 of 10

Replacement Code for TextJoin Function

  1. #1
    Registered User
    Join Date
    08-02-2023
    Location
    Cortland, NY
    MS-Off Ver
    365
    Posts
    4

    Replacement Code for TextJoin Function

    Hi All,

    Looking for some help generating a VBA code that replaces the TextJoin function in my Code. I am using a userform submission to open and create a pre-formatted email. After completing the code we releaized that not everyone that was using it was upgraded to Excel 365 and therefore cannot us the TextJoin function. I have posted the code below. Could someone please help generate an alternate formula that would do the same thing? (combine checkbox tags, remove blanks and separate with a comma) Thanks for the help!!


    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Hello," & vbNewLine & vbNewLine & _
    "A new incident report has been created: " & vbNewLine & _
    "Incident Type: " & Me.tb15.Value & vbNewLine & vbNewLine & _
    "Facility: " & Me.Facility.Value & vbNewLine & _
    "Incident Date: " & Me.IncidentDate.Value & vbNewLine & _
    "Incident Time: " & Me.IncidentHour.Value & ":" & Me.IncidentMinute.Value & vbNewLine & vbNewLine & _
    "Worker Job Title: " & Me.WorkerJobTitle.Value & vbNewLine & _
    "Location of Incident: " & Me.Location.Value & vbNewLine & _
    "Incident Description: " & Me.Description.Value & vbNewLine & _
    "Description of Injury/Illness: " & Me.Injury.Value & vbNewLine & _
    "Onsite First-Aid: " & Me.OnsiteExplain.Value & vbNewLine & _
    "Offsite Medical Treatment: " & Me.OffsiteLocation.Value & vbNewLine & vbNewLine & _
    "Contributing Factors: " & WorksheetFunction.TextJoin(", ", True, Me.Chemical.Tag, Me.Temperature.Tag, Me.Pressure.Tag, Me.HazardousEnergy.Tag, Me.PoorHousekeeping.Tag, Me.SlipperySurface.Tag, Me.PoorVisibility.Tag, Me.Noisy.Tag, Me.UnevenFloor.Tag, Me.EquipMalfunction.Tag, Me.SharpProtruding.Tag, Me.DamagedEquipment.Tag, Me.LeakDrip.Tag, Me.InsufficientSafetyDevice.Tag, Me.NotFollowingSOP.Tag, Me.Inexperienced.Tag, Me.Rushing.Tag, Me.NotWearingPPE.Tag, Me.PoorTechnique.Tag, Me.InadequateTraining.Tag, Me.PoorDesign.Tag, Me.MissingProcedures.Tag, Me.WorkloadStaffing.Tag, Me.InadequateMaintenance.Tag) & vbNewLine & _
    "Immediate Corrective Actions: " & Me.CorrectiveActions.Value & vbNewLine & vbNewLine & _
    "Thank you"

    On Error Resume Next
    With xOutMail
    .To = "example email" ''''Change TO Recipient Here
    .CC = ""
    .BCC = ""
    .Subject = "FROI - " & Me.tb15.Value & " - " & Me.Facility.Value ''''Change Subject Line Here
    .Attachments.Add
    .body = xMailBody
    .Display
    End With

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,945

    Re: Replacement Code for TextJoin Function

    Given that looks like a lot of individual fields, what's the advantage of using TEXTJOIN? Why not just scrap it and drop in a load more ampersands?

    So that would look like:
    Please Login or Register  to view this content.
    Tedious but doable.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Replacement Code for TextJoin Function

    This would omit blank tags

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    08-02-2023
    Location
    Cortland, NY
    MS-Off Ver
    365
    Posts
    4

    Re: Replacement Code for TextJoin Function

    Thanks for the response, I started with that originally, but couldn't figure out how to omit the blank Tags. The textjoin allowed me to do that.

  5. #5
    Registered User
    Join Date
    08-02-2023
    Location
    Cortland, NY
    MS-Off Ver
    365
    Posts
    4

    Re: Replacement Code for TextJoin Function

    Thanks AlphaFrog, I am now getting a syntax error, I am guessing that I need to surround that section of code with something. Any suggestion?

    Please Login or Register  to view this content.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,945

    Re: Replacement Code for TextJoin Function

    Put that code before you build the message body. Then replace the whole of the TextJoin section with the new variable x.

    "Contributing Factors: " & WorksheetFunction.TextJoin(", ", True, . . . ) becomes "Contributing Factors: " & x

  7. #7
    Registered User
    Join Date
    08-02-2023
    Location
    Cortland, NY
    MS-Off Ver
    365
    Posts
    4

    Re: Replacement Code for TextJoin Function

    Thank you AlphaFrog and TMS. It seems to work!!

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,945

    Re: Replacement Code for TextJoin Function

    You're welcome.



    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,945

    Re: Replacement Code for TextJoin Function

    Thanks for the rep.

  10. #10
    Valued Forum Contributor
    Join Date
    11-27-2011
    Location
    usa
    MS-Off Ver
    Excel 2007, Excel 365
    Posts
    495

    Re: Replacement Code for TextJoin Function

    The following is what I have saved in my toolbox of goodies:

    Please Login or Register  to view this content.
    Copy that into a regular module and you shouldn't need to change your TextJoin formula at all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] TextJoin function not working in 2016
    By abduljaleel.mca in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-18-2021, 09:47 AM
  2. Textjoin function based on changing row number
    By sam-using-xl in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-21-2019, 09:17 PM
  3. Textjoin and if function need help
    By bitozi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-23-2019, 06:35 AM
  4. Use two conditions in textjoin function in excel 2013.
    By magfas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-15-2018, 04:42 PM
  5. Function similar to textjoin
    By Allerdrengen in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-07-2018, 06:54 AM
  6. [SOLVED] TextJoin formula with MID function
    By Brsth in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-26-2018, 11:00 AM
  7. TEXTJOIN function
    By Tony Valko in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-13-2016, 06:48 PM

Tags for this Thread

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.6.0 RC 1