Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Replacing & during conversion of Excel to XML using VBA

Replacing & during conversion of Excel to XML using VBA

Scheduled Pinned Locked Moved Visual Basic
helpxml
11 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P priyaahh

    Hi Friends, I am converting an excel to xml using vba. THere this excel data having &. But when converting & to xml it is giving error. So I am using the following funtion to replace &. Function RemoveAmpersands(AnyStr As String) As String Dim MyPos As Integer ' replace Ampersands (&) with plus symbols (+) MyPos = InStr(1, AnyStr, "&") Do While MyPos > 0 Mid(AnyStr, MyPos, 1) = "+" MyPos = InStr(1, AnyStr, "&") Loop End But the above function replacing with +. But I wanted to display in the browser as & only. Kindly Help. Regards, Priya.

    R Offline
    R Offline
    riced
    wrote on last edited by
    #2

    Would using & fix the problem? Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.

    P 2 Replies Last reply
    0
    • P priyaahh

      Hi Friends, I am converting an excel to xml using vba. THere this excel data having &. But when converting & to xml it is giving error. So I am using the following funtion to replace &. Function RemoveAmpersands(AnyStr As String) As String Dim MyPos As Integer ' replace Ampersands (&) with plus symbols (+) MyPos = InStr(1, AnyStr, "&") Do While MyPos > 0 Mid(AnyStr, MyPos, 1) = "+" MyPos = InStr(1, AnyStr, "&") Loop End But the above function replacing with +. But I wanted to display in the browser as & only. Kindly Help. Regards, Priya.

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #3

      Forgot how to use code blocks already? Did you get your previous xml problem working in the end, didn't hear any more in the thread?

      Dave Don't forget to rate messages!
      Find Me On: Web|Facebook|Twitter|LinkedIn
      Waving? dave.m.auld[at]googlewave.com

      P 1 Reply Last reply
      0
      • P priyaahh

        Hi Friends, I am converting an excel to xml using vba. THere this excel data having &. But when converting & to xml it is giving error. So I am using the following funtion to replace &. Function RemoveAmpersands(AnyStr As String) As String Dim MyPos As Integer ' replace Ampersands (&) with plus symbols (+) MyPos = InStr(1, AnyStr, "&") Do While MyPos > 0 Mid(AnyStr, MyPos, 1) = "+" MyPos = InStr(1, AnyStr, "&") Loop End But the above function replacing with +. But I wanted to display in the browser as & only. Kindly Help. Regards, Priya.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        priyaahh wrote:

        I am using the following funtion to replace &.

        Your code replaces all the ampersands (&) in a string with plus (+) which is what you say you want to do. Then you say:

        priyaahh wrote:

        But the above function replacing with +. But I wanted to display in the browser as & only.

        ...so, what exactly do want to achieve? BTW this would do the same thing in one line.

        Dim newStr As String = AnyStr.Replace("&", "+")

        It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

        P 1 Reply Last reply
        0
        • L Lost User

          priyaahh wrote:

          I am using the following funtion to replace &.

          Your code replaces all the ampersands (&) in a string with plus (+) which is what you say you want to do. Then you say:

          priyaahh wrote:

          But the above function replacing with +. But I wanted to display in the browser as & only.

          ...so, what exactly do want to achieve? BTW this would do the same thing in one line.

          Dim newStr As String = AnyStr.Replace("&", "+")

          It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

          P Offline
          P Offline
          priyaahh
          wrote on last edited by
          #5

          Hi Thanks. Yes my code is replacing & with +. Because if i display as & in XML it is giving error. But i wanted to display & as & not as +. Is there any wy to display & in XML browser. Regards, Priya.

          L 1 Reply Last reply
          0
          • D DaveAuld

            Forgot how to use code blocks already? Did you get your previous xml problem working in the end, didn't hear any more in the thread?

            Dave Don't forget to rate messages!
            Find Me On: Web|Facebook|Twitter|LinkedIn
            Waving? dave.m.auld[at]googlewave.com

            P Offline
            P Offline
            priyaahh
            wrote on last edited by
            #6

            Hi Dave, Thanks. I think you are talking abt the function i ve written..without returning that function..with function name.. I have that line in my code..since it is big code i just copy pasted only first part and end function missed to paste last to previus line. Here is the function: Function RemoveAmpersands(AnyStr As String) As String Dim MyPos As Integer ' replace Ampersands (&) with plus symbols (+) MyPos = InStr(1, AnyStr, "&") Do While MyPos > 0 Mid(AnyStr, MyPos, 1) = "+" MyPos = InStr(1, AnyStr, "&") Loop RemoveAmpersands = AnyStr End Function If you are trying to say something pls reply.. Thanks Priya

            1 Reply Last reply
            0
            • R riced

              Would using & fix the problem? Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.

              P Offline
              P Offline
              priyaahh
              wrote on last edited by
              #7

              HI Thanks. I have not tried it ..let me try and reply Thanks, Priya.

              1 Reply Last reply
              0
              • R riced

                Would using & fix the problem? Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.

                P Offline
                P Offline
                priyaahh
                wrote on last edited by
                #8

                Hi, & is not working. Its going into infinitely....Any other approach to implement this? Thanks, Priya.

                1 Reply Last reply
                0
                • P priyaahh

                  Hi Thanks. Yes my code is replacing & with +. Because if i display as & in XML it is giving error. But i wanted to display & as & not as +. Is there any wy to display & in XML browser. Regards, Priya.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  Then riced's answer (above) is what you need. I found this with Google http://articles.techrepublic.com.com/5100-10878_11-5032714.html[^] Here's an extract: Ampersand—&—& greater-than—>—> less-than—<—< apostrophe—'—' quote—"—" If I may say so, you seem to make a lot of work for yourself!

                  It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

                  P 1 Reply Last reply
                  0
                  • L Lost User

                    Then riced's answer (above) is what you need. I found this with Google http://articles.techrepublic.com.com/5100-10878_11-5032714.html[^] Here's an extract: Ampersand—&—& greater-than—>—> less-than—<—< apostrophe—'—' quote—"—" If I may say so, you seem to make a lot of work for yourself!

                    It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

                    P Offline
                    P Offline
                    priyaahh
                    wrote on last edited by
                    #10

                    Hi Annie, Thanks for your reply. I tried using & but when i use this, I am not getting any output and the application is processing.....and not stopping..I have to use TaskManager and End the application. Kindly help. Regards, Priya.

                    L 1 Reply Last reply
                    0
                    • P priyaahh

                      Hi Annie, Thanks for your reply. I tried using & but when i use this, I am not getting any output and the application is processing.....and not stopping..I have to use TaskManager and End the application. Kindly help. Regards, Priya.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      OK, here are two code snippets that illustrate what you need.

                      <p>
                      You can find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
                      title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
                      </p>

                      After the 152368 you see ampersand(&), letter a, letter m, letter p then semi-colon(;)? That is what is required in place of the &. This will do the replacement for you:

                             Dim newStr As String = oldStr.Replace("&", "&amp;")
                      

                      It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups