vba:将长字符串存储在带有特殊字符的变量中

时间:2010-08-27 17:41:12

标签: vba string

我需要在vba中设置一个等于this的字符串。我该怎么做?

<svg 
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   version="1.0"
   width="958.69"
   height="592.78998"
   id="svg2275"
   sodipodi:version="0.32"
   inkscape:version="0.46"
   sodipodi:docname="Map of USA with state names.svg"
   sodipodi:docbase="C:\temp\webdesign"
   inkscape:output_extension="org.inkscape.output.svg.inkscape"
   onload='Init(evt)'> 
  <metadata 
     id="metadata2625"> 
    <rdf:RDF> 
      <cc:Work 
         rdf:about=""> 
        <dc:format>image/svg+xml</dc:format> 
        <dc:type 
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> 
      </cc:Work> 
    </rdf:RDF> 
  </metadata> 
  <script type="text/ecmascript"><![CDATA[
      var SVGDocument = null;
      var SVGRoot = null;
      var SVGViewBox = null;
      var svgns = 'http://www.w3.org/2000/svg';
      var xlinkns = 'http://www.w3.org/1999/xlink';
      var toolTip = null;
      var TrueCoords = null;
      var tipBox = null;
      var tipText = null;
      var tipTitle = null;
      var tipDesc = null;

      var lastElement = null;
      var titleText = '';
      var titleDesc = '';


      function Init(evt)
      {
         SVGDocument = evt.target.ownerDocument;
         SVGRoot = document.documentElement;
         TrueCoords = SVGRoot.createSVGPoint();

         toolTip = SVGDocument.getElementById('ToolTip');
         tipBox = SVGDocument.getElementById('tipbox');
         tipText = SVGDocument.getElementById('tipText');
         tipTitle = SVGDocument.getElementById('tipTitle');
         tipDesc = SVGDocument.getElementById('tipDesc');
      };


      function GetTrueCoords(evt)
      {
         // find the current zoom level and pan setting, and adjust the reported
         //    mouse position accordingly
         var newScale = SVGRoot.currentScale;
         var translation = SVGRoot.currentTranslate;
         TrueCoords.x = (evt.clientX - translation.x)/newScale;
         TrueCoords.y = (evt.clientY - translation.y)/newScale;
      };




      function ShowTooltip(evt, turnOn)
      {
        try
         {
            if (!evt || !turnOn)
            {
               toolTip.setAttributeNS(null, 'display', 'none');
            }
            else
            {
               var tipScale = 1/SVGRoot.currentScale;
               var textWidth = 0;
               var tspanWidth = 0;
               var boxHeight = 20;

               tipBox.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
               tipText.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );

               var targetElement = evt.target;

               if ( lastElement != targetElement )
               {
                  var targetTitle = targetElement.getElementsByTagName('title').item(0);


                  if ( targetTitle )
                  {
                     titleText = targetTitle.firstChild.nodeValue;
                     tipTitle.firstChild.nodeValue = titleText;


                  }


                  var targetDesc = targetElement.getElementsByTagName('desc').item(0);


                  if ( targetDesc )
                  {
                     titleDesc = targetDesc.firstChild.nodeValue;
                     tipDesc.firstChild.nodeValue = titleDesc;
                  }
               }

               var xPos = TrueCoords.x + (10 * tipScale);
               var yPos = TrueCoords.y + (10 * tipScale);

               //return rectangle around object as SVGRect object
               var outline = tipText.getBBox();
               tipBox.setAttributeNS(null, 'width', Number(outline.width) + 10);
               tipBox.setAttributeNS(null, 'height', Number(outline.height) + 10);

               toolTip.setAttributeNS(null, 'transform', 'translate(' + xPos + ',' + yPos + ')');
               toolTip.setAttributeNS(null, 'display', 'inline');
            }
         }
         catch(er){}
       };

   ]]></script> 

  <defs 
     id="defs2623"> 
    <inkscape:perspective 
       sodipodi:type="inkscape:persp3d"
       inkscape:vp_x="0 : 296.39499 : 1"
       inkscape:vp_y="0 : 1000 : 0"
       inkscape:vp_z="958.69 : 296.39499 : 1"
       inkscape:persp3d-origin="479.345 : 197.59666 : 1"
       id="perspective364" /> 
  </defs> 
  <sodipodi:namedview 
     inkscape:window-height="721"
     inkscape:window-width="1024"
     inkscape:pageshadow="2"
     inkscape:pageopacity="0.0"
     guidetolerance="10.0"
     gridtolerance="10.0"
     objecttolerance="10.0"
     borderopacity="1.0"
     bordercolor="#666666"
     pagecolor="#ffffff"
     id="base"
     inkscape:zoom="5.6568542"
     inkscape:cx="182.21001"
     inkscape:cy="-2.904429"
     inkscape:window-x="-4"
     inkscape:window-y="-4"
     inkscape:current-layer="Frames"
     showgrid="false"
     inkscape:showpageshadow="false"
     showborder="true"
     borderlayer="true" /> 
  <rect 
     width="959.62299"
     height="595.63739"
     x="-0.40383524"
     y="-1.2939188"
     id="water"
     style="fill:#9ec7f3" /> 
  <path 
     style="fill:#f7d3aa;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
     d="M 923.03026,37.975518 C 922.57184,38.995849 921.76084,41.697403 921.76084,44.352463 C 921.76084,47.130382 919.49185,46.324054 921.76084,48.603761 C 922.79254,49.640303 925.33008,47.328371 926.83847,47.328371 C 928.64472,47.328371 928.45237,51.223763 930.22354,51.579668 C 932.37666,52.012321 934.08737,52.522241 936.14743,52.004798 C 938.36058,51.448909 939.8978,50.502312 942.49447,51.154539 C 943.89657,51.506717 946.44388,48.461872 947.14893,47.753502 C 949.30188,45.590391 946.8075,50.401063 946.7258,50.729408 C 946.0737,53.350095 949.5805,52.429926 951.38029,52.429926 C 954.13433,52.429926 955.03028,50.940072 955.61163,48.603761 C 955.78273,47.916101 952.46128,44.82413 952.22655,44.352463 C 951.88695,43.670052 955.05553,42.433288 956.45789,41.376556 C 959.00459,39.457537 958.11054,38.360573 956.88104,37.125259 C 955.02965,35.26515 952.06131,38.141523 950.95714,39.250906 C 949.94504,40.267774 946.8031,41.463423 945.45641,41.801685 C 943.67466,42.24922 941.73037,44.09862 940.37878,44.777594 C 938.61378,45.664254 936.79892,46.420756 934.87803,46.903242 C 933.25123,47.311861 930.50953,44.639791 929.80042,43.927334 C 928.30508,42.424964 926.15309,43.238719 924.7228,41.801685 C 923.48412,40.557171 928.92137,37.975518 923.03026,37.975518 z"
     id="path2688" /> 
  <path 
     style="fill:#f7d3aa;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
     d="M 932.45066,120.20861 C 930.56646,122.10171 935.15436,115.51342 935.80065,112.9161 C 936.52536,110.00362 937.67175,108.72666 939.15063,106.74551 C 940.64215,104.74745 940.82562,100.846 940.82562,98.33109 C 940.82562,94.697237 941.40826,97.831106 942.11259,95.000584 C 942.7806,92.315942 941.7297,88.409776 943.58217,87.944477 C 946.31731,87.257463 949.87769,86.619091 953.54955,83.492046 C 957.14099,80.433488 956.23335,75.558206 959.25049,72.526837 C 962.75189,69.00893 959.2677,69.09194 960.36716,64.673369 C 961.11108,61.683657 959.77892,57.791585 960.36715,54.576053 C 960.92452,51.529335 958.08102,54.747152 955.74777,54.747152 C 952.95531,54.747152 954.38524,49.767421 952.12739,54.304389 C 950.71186,57.148825 948.18573,56.79432 945.85059,57.380865 C 944.22798,57.788431 941.05298,57.003598 939.15063,57.48143 C 936.94013,58.03666 936.27191,56.669364 933.72007,57.310332 C 930.25974,58.179495 930.66732,61.846501 929.98207,64.230607 C 929.29484,66.621592 924.71311,76.29826 926.47935,71.948243 C 928.45325,67.086805 924.8791,75.999318 926.84982,75.603312 C 929.51337,75.068093 934.29834,71.947646 937.07006,71.251447 C 938.8483,70.804793 941.9546,69.007602 943.78757,69.007602 C 946.05933,69.007602 937.01097,73.216374 935.64791,75.042351 C 933.89748,77.387265 932.85005,78.22614 930.48775,78.815618 C 927.67299,79.518007 930.51373,85.599379 927.5609,79.665878 C 926.27211,77.076125 925.69324,81.579246 924.07573,83.746077 C 922.03935,86.47405 923.3452,88.967737 920.72574,91.599545 C 917.87719,94.461523 918.61592,94.156215 918.49243,94.404355 C 916.99477,97.4138 915.70079,97.773488 915.70079,101.69687 C 915.70079,105.56604 916.81744,105.88691 916.81744,109.55032 C 916.81744,113.11165 916.61142,114.95296 918.49243,116.84284 C 920.32234,118.68138 922.63295,114.98367 924.88691,115.54981 C 926.91033,116.05805 932.04066,120.04384 935.24233,121.33052"
     id="path2715"
     sodipodi:nodetypes="csssssssssssssssssssssssssssssc" /> 
  <g 
     transform="matrix(1.0043294,0,0,1.0090644,-19.932863,-136.40509)"
     id="States"> 


    <path 
       d="M 242.96145,653.59282 L 244.83646,650.1553 L 247.02397,649.8428 L 247.33647,650.62405 L 245.30521,653.59282 L 242.96145,653.59282 z M 252.80525,649.99905 L 258.74278,652.49906 L 260.77404,652.18656 L 262.33654,648.43654 L 261.71154,645.15528 L 257.64902,644.68653 L 253.74275,646.40528 L 252.80525,649.99905 z M 282.49289,659.6866 L 286.08665,664.99912 L 288.43041,664.68662 L 289.52417,664.21787 L 290.93042,665.46787 L 294.52419,665.31162 L 295.4617,663.90537 L 292.64918,662.18661 L 290.77417,658.59284 L 288.74291,655.15533 L 283.11789,657.96784 L 282.49289,659.6866 z M 302.02423,668.28039 L 303.27423,666.40538 L 307.8055,667.34288 L 308.43051,666.87413 L 314.36803,667.49913 L 314.05553,668.74914 L 311.55552,670.15539 L 307.33675,669.84289 L 302.02423,668.28039 z M 307.1805,673.28041 L 309.05551,677.03043 L 312.02427,675.93667 L 312.33677,674.37416 L 310.77427,672.3429 L 307.1805,672.0304 L 307.1805,673.28041 z M 313.89928,672.18665 L 316.08679,669.37414 L 320.61806,671.7179 L 324.83683,672.81166 L 329.0556,675.46792 L 329.0556,677.34293 L 325.61809,679.06169 L 320.93056,679.99919 L 318.5868,678.59293 L 313.89928,672.18665 z M 329.99311,687.18672 L 331.55561,685.93672 L 334.83688,687.49923 L 342.18066,690.93674 L 345.46193,692.968 L 347.02443,695.31176 L 348.89944,699.53053 L 352.80571,702.03054 L 352.49321,703.28055 L 348.74319,706.40556 L 344.68067,707.81182 L 343.27442,707.18682 L 340.30565,708.90557 L 337.96189,712.03059 L 335.77438,714.8431 L 334.05562,714.68685 L 330.61811,712.18684 L 330.30561,707.81182 L 330.93061,705.46806 L 329.3681,699.99928 L 327.33684,698.28052 L 327.18059,695.78051 L 329.3681,694.84301 L 331.39936,691.87425 L 331.86811,690.93674 L 330.30561,689.21798 L 329.99311,687.18672 z"
       id="HI"
       style="fill:#ffffd0"  onmousemove=' GetTrueCoords(evt); ShowTooltip(evt, true)' onmouseout='ShowTooltip(evt, false)' > 
       <title>first name, last name</title>

    </path>   

    <path 
       d="M 170.46112,590.15502 L 170.14862,672.65541 L 171.71112,673.59291 L 174.67989,673.74916 L 176.08614,672.65541 L 178.58615,672.65541 L 178.74241,675.46792 L 185.46119,682.03045 L 185.92994,684.53046 L 189.2112,682.65545 L 189.83621,682.4992 L 190.14871,679.53044 L 191.55496,677.96793 L 192.64872,677.81168 L 194.52373,676.40542 L 197.49249,678.43668 L 198.1175,681.2492 L 199.9925,682.34295 L 201.08626,684.68671 L 204.83628,686.40547 L 208.11754,692.18675 L 210.7738,695.93676 L 212.96131,698.59303 L 214.36757,702.18679 L 219.21134,703.90555 L 224.21137,705.93681 L 225.14887,710.15558 L 225.61762,713.12434 L 224.68012,716.40561 L 222.96136,718.59312 L 221.39885,717.81187 L 219.9926,714.8431 L 217.33633,713.43685 L 215.61758,712.34309 L 214.83632,713.12434 L 216.24258,715.78061 L 216.39883,719.37437 L 215.30507,719.84312 L 213.43007,717.96812 L 211.39881,716.71811 L 211.86756,718.28062 L 213.11756,719.99938 L 212.33631,720.78063 C 212.33631,720.78063 211.55506,720.46813 211.08631,719.84312 C 210.61755,719.21812 209.05505,716.56186 209.05505,716.56186 L 208.11754,714.37435 C 208.11754,714.37435 207.80504,715.62436 207.18004,715.31185 C 206.55503,714.99935 205.93003,713.9056 205.93003,713.9056 L 207.64879,712.03059 L 206.24253,710.62433 L 206.24253,705.78056 L 205.46128,705.78056 L 204.68003,709.06182 L 203.58627,709.53058 L 202.64877,705.93681 L 202.02376,702.34304 L 201.24251,701.87429 L 201.55501,707.34307 L 201.55501,708.43682 L 200.14875,707.18682 L 196.71124,701.40554 L 194.67998,700.93679 L 194.05498,697.34302 L 192.49247,694.53051 L 190.92996,693.43675 L 190.92996,691.24924 L 192.96122,689.99924 L 192.49247,689.68674 L 189.99246,690.31174 L 186.71119,687.96798 L 184.21118,685.15546 L 179.52366,682.65545 L 175.61739,680.15544 L 176.8674,677.03043 L 176.8674,675.46792 L 175.14864,677.03043 L 172.33613,678.12418 L 168.74236,677.03043 L 163.27358,674.68667 L 157.96106,674.68667 L 157.33606,675.15542 L 151.08603,671.4054 L 149.05477,671.0929 L 146.39851,665.46787 L 142.96099,665.78037 L 139.52347,667.18663 L 139.99223,671.56165 L 141.08598,668.74914 L 142.02349,669.06164 L 140.61723,673.28041 L 143.74224,670.62415 L 144.36725,672.18665 L 140.61723,676.40542 L 139.36722,676.09292 L 138.89847,674.21791 L 137.64847,673.43666 L 136.39846,674.53042 L 133.7422,672.81166 L 130.77343,674.84292 L 129.05468,676.87418 L 125.77341,678.90544 L 121.24214,678.74918 L 120.77339,676.71793 L 124.36715,676.09292 L 124.36715,674.84292 L 122.17964,674.21791 L 123.11715,671.87415 L 125.30466,668.12414 L 125.30466,666.40538 L 125.46091,665.62412 L 129.67968,663.43661 L 130.61718,664.68662 L 133.27345,664.68662 L 132.02344,662.18661 L 128.42967,661.87411 L 123.5859,664.53037 L 121.24214,667.81163 L 119.52338,670.31165 L 118.42963,672.49916 L 114.36711,673.90541 L 111.39834,676.40542 L 111.08584,677.96793 L 113.27335,678.90544 L 114.05461,680.93669 L 111.39834,684.06171 L 105.14832,688.12423 L 97.648277,692.18675 L 95.617017,693.2805 L 90.460745,694.37426 L 85.304465,696.56177 L 87.023225,697.81177 L 85.616965,699.21803 L 85.148215,700.31178 L 82.491955,699.37428 L 79.366945,699.53053 L 78.585685,701.71804 L 77.648185,701.71804 L 77.960685,699.37428 L 74.523165,700.62429 L 71.710655,701.56179 L 68.42939,700.31178 L 65.616877,702.18679 L 62.491863,702.18679 L 60.460603,703.4368 L 58.898096,704.21805 L 56.866837,703.90555 L 54.366825,702.8118 L 52.179315,703.4368 L 51.241811,704.3743 L 49.679303,703.28055 L 49.679303,701.40554 L 52.648067,700.15553 L 58.741845,700.78054 L 62.960615,699.21803 L 64.991874,697.18677 L 67.804387,696.56177 L 69.523145,695.78051 L 72.179408,695.93676 L 73.741915,697.18677 L 74.679415,696.87427 L 76.866925,694.21801 L 79.835695,693.2805 L 83.116955,692.6555 L 84.366965,692.343 L 84.991965,692.81175 L 85.773225,692.81175 L 87.023225,689.21798 L 90.929495,687.81173 L 92.804505,684.21796 L 94.992017,679.84294 L 96.554527,678.43668 L 96.867027,675.93667 L 95.304517,677.18668 L 92.023245,677.81168 L 91.398245,675.46792 L 90.148245,675.15542 L 89.210735,676.09292 L 89.054485,678.90544 L 87.648225,678.74918 L 86.241975,673.12416 L 84.991965,674.37416 L 83.898215,673.90541 L 83.585715,672.0304 L 79.679445,672.18665 L 77.648185,673.28041 L 75.148175,672.96791 L 76.554425,671.56165 L 77.023175,669.06164 L 76.398175,667.18663 L 77.804435,666.24913 L 79.054435,666.09288 L 78.429435,664.37412 L 78.429435,660.15535 L 77.491935,659.21784 L 76.710675,660.6241 L 70.773151,660.6241 L 69.366895,659.37409 L 68.741892,655.62408 L 66.710632,652.18656 L 66.710632,651.24906 L 68.741892,650.4678 L 68.898142,648.43654 L 69.991897,647.34279 L 69.210644,646.87404 L 67.960638,647.34279 L 66.866883,644.68653 L 67.804387,639.84275 L 72.179408,636.71774 L 74.679415,635.15523 L 76.554425,631.56147 L 79.210695,630.31146 L 81.710705,631.40522 L 82.023205,633.74898 L 84.366965,633.43647 L 87.491975,631.09271 L 89.054485,631.71772 L 89.991985,632.34272 L 91.554495,632.34272 L 93.742007,631.09271 L 94.523267,626.87394 C 94.523267,626.87394 94.835767,624.06143 95.460767,623.59268 C 96.085767,623.12393 96.398267,622.65518 96.398267,622.65518 L 95.304517,620.78017 L 92.804505,621.56142 L 89.679485,622.34267 L 87.804475,621.87392 L 84.366965,620.15516 L 79.523195,619.99891 L 76.085675,616.40515 L 76.554425,612.65513 L 77.179435,610.31137 L 75.148175,608.59261 L 73.273163,604.99884 L 73.741915,604.21759 L 80.304445,603.74884 L 82.335705,603.74884 L 83.273205,604.68634 L 83.898215,604.68634 L 83.741965,603.12383 L 87.491975,602.49883 L 89.991985,602.81133 L 91.398245,603.90509 L 89.991985,605.93635 L 89.523235,607.3426 L 92.179505,608.90511 L 97.023277,610.62387 L 98.742037,609.68637 L 96.554527,605.4676 L 95.617017,602.34258 L 96.554527,601.56133 L 93.273257,599.68632 L 92.804505,598.59256 L 93.273257,597.03006 L 92.492005,593.28004 L 89.679485,588.74877 L 87.335725,584.68625 L 90.148245,582.81124 L 93.273257,582.81124 L 94.992017,583.43624 L 99.054537,583.27999 L 102.6483,579.84248 L 103.74206,576.87371 L 107.33583,574.52995 L 108.89833,575.46746 L 111.55459,574.84245 L 115.14836,572.81119 L 116.24212,572.65494 L 117.17962,573.4362 L 121.55464,573.27995 L 124.2109,570.31118 L 125.30466,570.31118 L 128.74217,572.65494 L 130.61718,574.6862 L 130.14843,575.77996 L 130.77343,576.87371 L 132.33594,575.31121 L 136.08596,575.62371 L 136.39846,579.21747 L 138.27347,580.62373 L 145.1485,581.24873 L 151.24228,585.31125 L 152.64853,584.37375 L 157.64856,586.87376 L 159.67982,586.24876 L 161.55483,585.4675 L 166.24235,587.34251 L 170.46112,590.15502 z M 59.210598,618.1239 L 61.241857,623.28018 L 61.085606,624.21768 L 58.273093,623.90518 L 56.554335,619.99891 L 54.835577,618.59266 L 52.491816,618.59266 L 52.335566,616.09264 L 54.054324,613.74888 L 55.148079,616.09264 L 56.554335,617.4989 L 59.210598,618.1239 z M 56.710586,650.4678 L 60.304353,651.24906 L 63.898119,652.18656 L 64.679373,653.12407 L 63.116866,656.71783 L 60.148102,656.56158 L 56.866837,653.12407 L 56.710586,650.4678 z M 36.710493,636.87399 L 37.804249,639.374 L 38.898004,640.93651 L 37.804249,641.71776 L 35.772989,638.749 L 35.772989,636.87399 L 36.710493,636.87399 z M 23.429182,707.49932 L 26.710447,705.31181 L 29.991712,704.3743 L 32.491724,704.6868 L 32.960476,706.24931 L 34.835485,706.71806 L 36.710493,704.84306 L 36.397992,703.28055 L 39.054254,702.65555 L 41.866767,705.15556 L 40.773012,706.87431 L 36.554243,707.96807 L 33.89798,707.49932 L 30.304214,706.40556 L 26.085444,707.81182 L 24.522937,708.12432 L 23.429182,707.49932 z M 70.773151,703.1243 L 72.335658,704.99931 L 74.366915,703.4368 L 72.960661,702.18679 L 70.773151,703.1243 z M 73.585664,706.09306 L 74.679415,703.90555 L 76.710675,704.21805 L 75.929425,706.09306 L 73.585664,706.09306 z M 96.398267,704.21805 L 97.804527,705.93681 L 98.742037,704.84306 L 97.960777,702.96805 L 96.398267,704.21805 z M 104.83581,692.18675 L 105.92957,697.81177 L 108.74208,698.59303 L 113.58585,695.78051 L 117.80462,693.2805 L 116.24212,690.93674 L 116.71087,688.59298 L 114.67961,689.84299 L 111.8671,689.06173 L 113.4296,687.96798 L 115.30461,688.74923 L 119.05463,687.03047 L 119.52338,685.62422 L 117.17962,684.84296 L 117.96087,682.96795 L 115.30461,684.84296 L 110.77334,688.28048 L 106.08582,691.09299 L 104.83581,692.18675 z M 145.7735,672.96791 L 148.11726,671.56165 L 147.17976,669.84289 L 145.461,670.7804 L 145.7735,672.96791 z"
       id="AK"
       style="fill:#f2d0ff" onmousemove=' GetTrueCoords(evt); ShowTooltip(evt, true)' onmouseout='ShowTooltip(evt, false)' > 
    <title>this sis ak</title>
    </path>

2 个答案:

答案 0 :(得分:3)

有点不清楚您打算如何检索并将数据存储到单个VBA字符串中,但是如果您打算复制并粘贴您发布的文本内容并在内存中以字符串形式提供在VBA中,您可以采用以下方式。

要记住的最重要的事情是逃避双引号和换行符。我将所有"替换为" & chr(34) & ",并在该行的末尾添加了vbCrLf。在VBA中使用时,文件的前几行可能如下所示:

Public Sub TestString()
    Dim str As String

    str = ""

    str = str & "<svg  " & vbCrLf
    str = str & "   xmlns:dc=" & Chr(34) & "http://purl.org/dc/elements/1.1/" & Chr(34) & " " & vbCrLf
    str = str & "   xmlns:cc=" & Chr(34) & "http://creativecommons.org/ns#" & Chr(34) & " " & vbCrLf
    str = str & "   xmlns:rdf=" & Chr(34) & "http://www.w3.org/1999/02/22-rdf-syntax-ns#" & Chr(34) & " " & vbCrLf
    str = str & "   xmlns:svg=" & Chr(34) & "http://www.w3.org/2000/svg" & Chr(34) & " " & vbCrLf
    str = str & "   xmlns=" & Chr(34) & "http://www.w3.org/2000/svg" & Chr(34) & " " & vbCrLf
    str = str & "   xmlns:sodipodi=" & Chr(34) & "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" & Chr(34) & " " & vbCrLf
    str = str & "   xmlns:inkscape=" & Chr(34) & "http://www.inkscape.org/namespaces/inkscape" & Chr(34) & " " & vbCrLf
    str = str & "   version=" & Chr(34) & "1.0" & Chr(34) & " " & vbCrLf
    str = str & "   width=" & Chr(34) & "958.69" & Chr(34) & " " & vbCrLf
    str = str & "   height=" & Chr(34) & "592.78998" & Chr(34) & " " & vbCrLf
    str = str & "   id=" & Chr(34) & "svg2275" & Chr(34) & " " & vbCrLf
    str = str & "   sodipodi:version=" & Chr(34) & "0.32" & Chr(34) & " " & vbCrLf


    Debug.Print str

End Sub

为了更容易生成str = str ...代码行,我将代码粘贴到Excel中并使用以下Excel公式,这样我就可以将生成的Excel计算文本直接粘贴到VBA编辑器中:< / p>

="str = str & " & CHAR(34) & SUBSTITUTE(A1,CHAR(34),CHAR(34) & " & chr(34) & " & CHAR(34)) & CHAR(34) & " & vbCrLf"

我尝试将您拥有的所有内容粘贴到VBA中,但原始文本的某些行太长(带数字的行)并在VBA编辑器中占用了多行。这可以通过将这些行拆分为多个str = str & ...行来解决,除非最后没有vbCrLf

答案 1 :(得分:0)

另一种方法是替换字符。

为了简化,你必须存储一个包含这个字符串的字符串:

  height="595.63739"

...然后,您可以用替换字符替换双引号,以这样的结尾替换:

  height=#595.63739#

......以及整个事情的代码:

str = "height=#595.63739#"
str = Replace(str, "#", Chr(34))

在那里,您的字符串更易于管理,因为它不需要额外的连接。

缺点:

  • 你可能会因为错误的char而烦恼 替代 - 在例子中,supose 实际上,你有一些“#” 字符串。
  • 我不确定 表现问题。
相关问题