user4798314
user4798314

Reputation:

Excel output to file

I've got list of SQL commands in an excel sheet. Similar to this:

update table1 set data =100 where point=123
update table1 set data =100 where point=421
update table1 set data =100 where point=12333
update table1 set data =100 where point=90

'4'

Where 4 represents count of commands.
What I need with them is export into .sql file and save.
I've found a great tutorial which helped me a lot but at the end of it there was a line saying not to worry about double quotes.
Well I do.

My code looks like this:

Sub OpenTextFile()

    Dim FilePath As String
    Dim LastRow As Long
    Dim CellData As String

    FilePath = ThisWorkbook.Path & "\" & "update.sql"
    LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
 
    Open FilePath For Output As #1
    For i = 1 To LastRow
        CellData = ActiveCell(i).Value
        Write #1, CellData
    Next i
    Close #1

End Sub

And exports data but I can't find a way to get rid of these quotes because output looks like:

update table1 set data =100 where point=123

And so on.

Upvotes: 0

Views: 160

Answers (1)

Sobigen
Sobigen

Reputation: 2179

Change Write #1, CellData to Print #1, CellData

That worked for me in my tests. Further reading here: https://msdn.microsoft.com/en-us/library/office/gg264278.aspx

Upvotes: 1

Related Questions