Driving me insane " marks and Chr(34)
Driving me insane " marks and Chr(34)
(OP)
Hi guys,
So this is driving me insane I have a macro which is exporting to a text file and I need the first line to be:
<ProjectInput xmlns="http://tempuri.org/ProjectInput.xsd">
I have tried the following codes with the following responses:
As expected
Cells(1, 1).Value = "<ProjectInput xmlns=" & "http://tempuri.org/ProjectInput.xsd" & ">"
gives
<ProjectInput xmlns=http://tempuri.org/ProjectInput.xsd>
but when I try to add the ""
Cells(1, 1).Value = "<ProjectInput xmlns=" & Chr(34) & "http://tempuri.org/ProjectInput.xsd" & Chr(34) & ">"
gives
"<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
Cells(1, 1).Value = "<ProjectInput xmlns=" & """http://tempuri.org/ProjectInput.xsd""" & ">"
gives
"<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
What's going wrong? (ps ignore the hyperlinks there not supposed to do that)
Thank you all for your help!
Kind Regards
Nick
So this is driving me insane I have a macro which is exporting to a text file and I need the first line to be:
<ProjectInput xmlns="http://tempuri.org/ProjectInput.xsd">
I have tried the following codes with the following responses:
As expected
Cells(1, 1).Value = "<ProjectInput xmlns=" & "http://tempuri.org/ProjectInput.xsd" & ">"
gives
<ProjectInput xmlns=http://tempuri.org/ProjectInput.xsd>
but when I try to add the ""
Cells(1, 1).Value = "<ProjectInput xmlns=" & Chr(34) & "http://tempuri.org/ProjectInput.xsd" & Chr(34) & ">"
gives
"<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
Cells(1, 1).Value = "<ProjectInput xmlns=" & """http://tempuri.org/ProjectInput.xsd""" & ">"
gives
"<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
What's going wrong? (ps ignore the hyperlinks there not supposed to do that)
Thank you all for your help!
Kind Regards
Nick





RE: Driving me insane " marks and Chr(34)
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Driving me insane " marks and Chr(34)
yes Chr(39) works fine and
Cells(1, 1).Value = "<ProjectInput xmlns=" & Chr(39) & "http://tempuri.org/ProjectInput.xsd" & Chr(39) & ">"
gives
<ProjectInput xmlns='http://tempuri.org/ProjectInput.xsd'>
So I dont see why Chr(34) does not work?
Cheers Nick
RE: Driving me insane " marks and Chr(34)
=CONCATENATE("<", CHAR(34), "test", CHAR(34), ">")
TTFN

FAQ731-376: Eng-Tips.com Forum Policies
Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers
RE: Driving me insane " marks and Chr(34)
Cheers Nick
RE: Driving me insane " marks and Chr(34)
If the line were to read as follows:
"<ProjectInput xmlns="http://tempuri.org/ProjectInput.xsd">"
The ambiguity is whether the quote that comes immediately after the equal sign is to start a second quote or to close the quote that begins the line. Is this:
"<ProjectInput xmlns=" & "http://tempuri.org/ProjectInput.xsd & ">"
or is it
"<ProjectInput xmlns= & "http://tempuri.org/ProjectInput.xsd" & >"
The ambiguity is resolved by using two consecutive quote to signify that the second interpretation is correct.
"<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
However, it's much easier both to code and to read by using double quotes on the outside and single quotes on the inside, or vise versa, single quotes on the outside and double quotes on the inside.
"<ProjectInput xmlns='http://tempuri.org/ProjectInput.xsd'>"
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Driving me insane " marks and Chr(34)
"<ProjectInput xmlns=" & http://tempuri.org/ProjectInput.xsd & ">"
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Driving me insane " marks and Chr(34)
CODE
or, if you are concatenating 3 string variables, try this:
CODE
www.nxjournaling.com
RE: Driving me insane " marks and Chr(34)
I tried using Cells (1,1) = "<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
and as you say "" is essentially saying " as text so I would expect to yield
<ProjectInput xmlns="http://tempuri.org/ProjectInput.xsd">
but it outputted "<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
Cowski, I tried your code and it also still gave:
"<ProjectInput xmlns=""http://tempuri.org/ProjectInput.xsd"">"
It keeps adding the extra bits in red which I dont want.
I though that in general when defining a string the "" marks are ignored i.e.
Cells (1,1) = "string" would give an output of string not "string" so I dont understand where they are coming from.
RE: Driving me insane " marks and Chr(34)
I tested my code examples in Excel 2010 and the output to the cell is in the format you wanted (I have not tried exporting these values to a text file).
RE: Driving me insane " marks and Chr(34)
I am also on excel 2010 just checked and yes in the actual Cell it reads correct as:
<ProjectInput xmlns="http://tempuri.org/ProjectInput.xsd">
somehow when exporting my worksheet as a text file its adding extra " marks ?
The relvant code for exporting the worksheet is essentially:
Dim ws As String
Dim Output As Workbook
ws = "name of worksheet"
Worksheets(ws).Copy
Set Output = ActiveWorkbook
Output.SaveAs "C:filepath\" & ws & ".extension", xlTextWindows
Output.Close SaveChanges:=False
Cheers,
Nick
RE: Driving me insane " marks and Chr(34)
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein