export result of a macro to a text file

nehachoubey

Board Regular
Joined
Aug 17, 2011
Messages
52
Hi,
i have written a macro in my workbook whose result is in sheet2. I have to export the result in a text file. it will be done through a .bat or .csv file. plz help!!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Sub Test()
Dim LR As Integer
Dim LR2 As Integer

With Sheets("Sheet1")
LR = .Range("A" & Rows.Count).End(xlUp).Row
LR2 = .Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LR
'For j = 2 To LR2
If Sheets("Sheet1").Range("B" & i).Value = "" Then
Sheets("Sheet2").Range("A" & i).Value = "SELECT " + "'" & Sheets("Sheet1").Range("A" & i).Value & "' NAME " & " FROM DUAL UNION"

ElseIf Sheets("Sheet1").Range("B" & i).Value = "<Mention the folder name(s) for which permission is required>" Then
Sheets("Sheet2").Range("A" & i).Value = "SELECT * FROM DUAL UNION"

Else
Sheets("Sheet2").Range("A" & i).Value = "SELECT " + "'" & Sheets("Sheet1").Range("A" & i).Value & "' NAME,'" _
& Sheets("Sheet1").Range("B" & i).Value & "' VALUE FROM DUAL UNION"
End If




Next i

End With

End Sub
 
Upvote 0
maybe...
Code:
    Sheets("Sheet2").Copy
    ActiveWorkbook.SaveAs Filename:="C:\XLtest\Book1.csv", _
                          FileFormat:=xlCSV, _
                          CreateBackup:=False
    ActiveWorkbook.Close False
 
Upvote 0
thanks for this but actually i want to perform this action thought a batch or a vbs file.. the point is that i need not open the excel at all. Just provide the excel file path.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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
Back
Top