Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8859429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:03:38+00:00 2026-06-14T15:03:38+00:00

I need help with the creation of an Excel VBA-function. A string variable mystring

  • 0

I need help with the creation of an Excel VBA-function.

A string variable “mystring” can have three different formats.

The first is just a normal text string. Nothing needed for this case.
The other two versions are needed to handle tags and href links for a later html output.

Excel Example:

mystring = "This is a headline"
mystring = "<myLink href='some/link.html'</myLink> This is also a headline"
mystring = "<noLink href='#'</noLink> This is another headline"

So, I need to identify if the string contains a myLink or noLink tag and assign the according href to an xml href-attribute.
For noLink it’s more userfriendly to just write the <nolink>-tag and let the function add the href='#', I believe.

I am open to suggestions if there’s a better way to set up those delimiters.

Also, the actually headline text is part of the xml-tag and later used for the mystringName xml-attribute.

For the above examples these should be the resulting xml tags:

<mytag mystringName="This is a headline"/>
<mytag mystringName="This is also a headline" href="some/link.html" />
<mytag mystringName="This is another headline" href="#" />

With the help of XSL I can then deal with the different href attributes.

How I think this could be used inside VBA:

If mystring = "myLink" Then
xmf.writeline "<mytag mystringName=""" & mystring & """href= """ & href & """ > """
End If

I have stumpled over this function I found online:
I would need to write the delimiter a bit differently.
"<myLink href=some/link.html>"This is also a headline
Maybe this is a good starting point to split the pieces and put them in an array.

Public Function GetStringFromQuotation(ByRef sText, sDelimiter As String)
     'Store the position of the 1st and 2nd delimiter in the String
    Dim iPositionOfFirstDelimiter As Integer, iPositionOfSecondDelimiter As Integer
     'Store the length of the delimiter
    Dim iLenDelimiter As Integer

     'Deliver nothing if the function doesn't get a single usable parameter
     'otherwise you'd get an error later on
    If Len(sText) = 0 And Len(sDelimiter) = 0 Then
        GetStringFromQuotation = ""
        Exit Function
    End If

    iLenDelimiter = Len(sDelimiter)
     'Find 1st occurence of delimiter
    iPositionOfFirstDelimiter = InStr(sText, sDelimiter)
     'Find the 2nd one, starting right behind the first one
    iPositionOfSecondDelimiter = InStr(iPositionOfFirstDelimiter + iLenDelimiter, _
    sText, sDelimiter)

     'If there are 2 occurences
    If iPositionOfFirstDelimiter > 0 And iPositionOfSecondDelimiter > 0 Then
         'Take the part of the string that's right between them
        GetStringFromQuotation = Mid(sText, iPositionOfFirstDelimiter + iLenDelimiter,     _
        iPositionOfSecondDelimiter - iPositionOfFirstDelimiter - iLenDelimiter)
    Else
        GetStringFromQuotation = ""
    End If
End Function

Hope you can help me to get this function (or some other) to work.

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:03:40+00:00Added an answer on June 14, 2026 at 3:03 pm

    If I understand correctly, your string can potentially have 1 or 3 sections. I would use a single delimiter (of one or more characters) to separate these sections, and drop the single-quotes, as follows:

    'Using a semicolon
    mystring = "This is a headline"
    mystring = "myLink;some/link.html;This is also a headline"
    mystring = "noLink;#;This is another headline"
    

    The function you write can then look like this:

    Public Function GetXML(str As String) As String
    Dim mylinkPos As Integer, nolinkPos As Integer
    Dim remainderString As String, nextDelimiterPos As String
    Dim href As String, headline As String
    
    mylinkPos = InStr(str, "mylink;")
    nolinkPos = InStr(str, "nolink;")
    
    If mylinkPos = 0 And nolinkPos = 0 Then
        GetXML = "<mytag mystringName=""" & str & """ />"
        Exit Function
    End If
    
    remainderString = Mid(str, 8)
    If nolinkPos > 0 Then
        headline = remainderString
        href = "#"
    Else
        nextDelimiterPos = InStr(remainderString, ";")
        href = Left(remainderString, nextDelimiterPos - 1)
        headline = Mid(remainderString, nextDelimiterPos + 1)
    End If
    
    GetXML = "<mytag mystringName=""" & headline & """ href=""" & href & """ />"
    End Function
    

    Of course, it would be much simpler and more elegant to use regular expressions, which you can use by adding a reference to Microsoft VBScript Regular Expressions 5.5 from Tools -> References.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help with a query that I wrote: I have three tables Company id
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
need help/guide for sql select query, I have 2 table stock and stock_history, in
need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:
I need help with one ajax function This is raw page setup. Page will
Can someone help me with creation of a url previews in JavaScript? What I
I need to have a button automatically click. Either on the creation of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.