user1766080
user1766080

Reputation: 631

VBA StringBetween

i have a little problem.

I want to get the Version Number from my Site, which is stored like that:

<version>1</version>

How can i get the Number between that 2 Strings into a variable?

Im completly new to vba and just need it for a simple check.

Thanks

//EDIT:

Tried now:

            Data = .responseText
        version = Replace(Replace(Data, "<version>", vbNullString), "</version>", vbNullString)
        If version > Cells(2, 3) Then
           strTitle = "new version"
           strPrompt = "new version available"
           iRet = MsgBox(strPrompt, vbOKOnly + vbExclamation, strTitle)
        End If

In the Cell there is a "1" also on the site a:

<version>1</version>

But everytime i run it the msgbox pop up..

I just testewd it. The version aswell the cell output = 1. DOnt know why it wont work then

Upvotes: 0

Views: 72

Answers (3)

InContext
InContext

Reputation: 2501

in VBA:

Dim Data As String, cleanData As String

Data = "<version>1</version>"

cleanData = Replace(Replace(Data, "<version>", vbNullString), "</version>", vbNullString)

In Excel where B57 is the text "1":

LEFT(RIGHT(B57, LEN(B57) - FIND(">",B57)), 1)

Upvotes: 2

PowerUser
PowerUser

Reputation: 11801

If this is already stored in a string, then a simple answer might be:

replace(
    replace(myString,"<version>","")
,"</version>","")

Basically, just replace the first half of your string with nothing, then replace the second half with nothing, leaving just the number.

Upvotes: 0

John Bustos
John Bustos

Reputation: 19574

... Given that you know it will be surrounded by those 2 words specifically, you oculd use something like:

MyVersion = Replace(Replace(x, "<version>", ""), "</version>", "")

Upvotes: 0

Related Questions