57202

VBA code in excel to made text between tags bold

Question:

I have a csv file which includes the html tags < b > and <\ b > to signify bold text. (I.e several words between these tags, in a longer block of text within the cell, should be bold). Is there a way using vba code in excel to strip the tags, and make the text between the tags bold?

Note - There are sometime multiple sets of tags within a given cell.

Answer1:

This should do what you want:

Sub BoldTags() Dim X As Long, BoldOn As Boolean BoldOn = False 'Default from start of cell is not to bold For X = 1 To Len(ActiveCell.Text) If UCase(Mid(ActiveCell.Text, X, 3)) = "<B>" Then BoldOn = True ActiveCell.Characters(X, 3).Delete End If If UCase(Mid(ActiveCell.Text, X, 4)) = "</B>" Then BoldOn = False ActiveCell.Characters(X, 4).Delete End If ActiveCell.Characters(X, 1).Font.Bold = BoldOn Next End Sub

Currently set to run on the activecell, you can just plop it in a loop to do a whole column. You can easily adapt this code for other HTML tags for Cell formatting (ie italic etc)

This was in the cell I tested on (minus the space after <): Sample < b>Te< /b>st of < B>bolding< /B> end

The result was: Sample <b>Te</b>st of <b>bolding</b> end

Hope that helps

Recommend

  • How to negative match regex in JavaScript string replace? [duplicate]
  • Grails 3 - How to publish to Artifactory
  • Efficiently reading a csv file with windows newline on linux in Python
  • How to initialize context? [closed]
  • Creating UDF with VSTO in Excel
  • Granting permissions to Azure Active Directory Web Application automatically
  • VBA Dir function not working on Excel 2010
  • Double-click autofill - dynamic based on adjacent cell
  • Excel VBA URLDownloadToFile Error for https Ressource
  • Outlook to Excel hyperlink issue
  • Android: How to correctly use NotifyDataSetChanged with SimpleExpandableListAdapter?
  • C# Excel interop - how to test if interop object is still working and performing a task?
  • Creating a Multidimensional, Associative Array in VBScript
  • Use tryCatch within R loop
  • In matplotlib, how do you change the fontsize of a single figure?
  • Is there some graphical way to create my own configuration file on SonarLint?
  • Javascript, Regex - I need to grab each section of a string contained in brackets
  • URLConnection doesn't work since API 10 and higher?
  • ASP.NET MVC 2 Preview 2 - display directory list rather than home/index
  • Is it possible to open regedit and navigate to straight to a specific key using process.start?
  • Entity Framework Code First TPC Inheritance Self-Referencing Child Class
  • Conversion from string “a” to type 'Boolean' is not valid
  • Content-Length header not returned from Pylons response
  • Play WS (2.2.1): post/put large request
  • Jetty Server not starting: Unable to establish loopback connection
  • How to access EntityManager inside Entity class in EJB3
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Android screen density dpi vs ppi
  • Bug in WPF DataGrid
  • Validaiting emails with Net.Mail MailAddress
  • vba code to select only visible cells in specific column except heading
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Javascript + PHP Encryption with pidCrypt
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • python regex in pyparsing
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Android Google Maps API OnLocationChanged only called once
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?