Write method adding erroneous quotes

koptastic69

New member
Local time
Today, 18:26
Joined
Mar 2, 2010
Messages
5
I have a web.config file that I wish to make two changes to. I read in the web.config file using the Line Input method to a table and make the two changes where appropriate. I then write out the file using the Write method. When I come to examine the output I have on every line superfluous quotation marks.

This is the input file;

<?xml version="1.0" encoding="utf-8"?>

This is the resulting file;

" <?xml version=""1.0"" encoding=""utf-8""?>"

As this is an xml file this matters quite considerably. How can I get VBA to write out the file without adding these extra quotes?

This is my code;

Public Function ImportFile(elementname As String, element As String)
Dim textline As String

Open elementname For Input As #1 ' Original web.config file
Open "c:\webNEW.config" For Output As #2 ' New copy of web.config file

Do While Not EOF(1)
Line Input #1, textline

If InStr(1, textline, "Data Source=DV1") Then
textline = Replace(textline, "Data Source=DV1", "Data Source=sql")
textline = Replace(textline, "Password=ironspeed", "Password=belkin")
Write #2, textline
Else
Write #2, textline
End If
Loop

Close #1
Close #2
End Function
 
Worked like a charm. Thanks very much.:o
 

Users who are viewing this thread

Back
Top Bottom