VBA Xml

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
190
Hi All

I have the below which is working fine
VBA Code:
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & "?>"

which produces
VBA Code:
<?xml version="1.0" encoding="UTF-8"?>

on the output xml fine. I need to change this to include standalone so
VBA Code:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>

can someone help me please as am getting bogged down on Chr(34) etc?
thanks
Noel
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,858
Office Version
  1. 2010
Platform
  1. Windows
Try it this way...

VBA Code:
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & " standalone=" & Chr(34) & "True" & Chr(34) & "?>"
 

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
190
Hi Rick, thanks for your response

when I run the code it is not producing anything. To be clear on what I did

I commented out the original (which does produce the xml) & pasted your code as below

VBA Code:
  'Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & "?>"
   Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & " standalone=" & Chr(34) & "True" & Chr(34) & "?>"
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,858
Office Version
  1. 2010
Platform
  1. Windows
If the code line you commented out works, the I would think what I posted has to work as well. Paste this into the Immediate Window in the VBA editor, then hit the Enter Key. It should print out what you said you wanted back in Message #1. All I did is remove the "print to file" command and replace it with VBA's Immediate Window print command.

VBA Code:
? "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & " standalone=" & Chr(34) & "True" & Chr(34) & "?>"
 

CephasOz

Board Regular
Joined
Feb 18, 2020
Messages
206
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
The easiest method is to double the internal double-quotes, like this:
VBA Code:
Print #1, "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""true""?>"
 

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
190
cool that worked, thanks CephasOz

For anyone else searching for the same issue, using "true" produced nothing, "yes" worked with the below and the "yes" then produces the True on the xml file

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

VBA Code:
Print #1, "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>"
 

Watch MrExcel Video

Forum statistics

Threads
1,127,330
Messages
5,624,046
Members
416,007
Latest member
csf

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top