How do I create an Excel Macro to output key/value pairs to file?

4

1

I have two columns as key/value pairs and want to export them to a file in the structure key=value (to create a properties file).

I tried this script:

Sub Properties()
Dim FileName As String, i As Integer, str As String

FileName = "C:\propstest.txt"

Open FileName For Output As #1

For i = 1 To 50
str = cells(i, 1) & "=" & cells(i, 2)
Write #1, str
Next i
Close #1

End Sub

It almost works but it prints to the file like

"key=value"

Is there a way to get rid of the quotation marks in the file?

Thanks.

jmcmahon

Posted 2010-10-22T21:01:19.697

Reputation: 318

Answers

4

Using WriteLine instead of Write should get rid of the quotation marks.

Stewbob

Posted 2010-10-22T21:01:19.697

Reputation: 444

I ended up changing the Write to Print and it worked. I think your way would have worked too, but I would have had to change more. – jmcmahon – 2011-05-12T19:53:24.727