Button to create CSV file
I've been given a task to create a button function in the Requirements module to produce a .CSV file of all the requirements. On the outset, I told them the easiest was to create the file via the Analysis module in Excel, but I was out voted.
So, I have the SQL query, I have the button and the button does open Notepad. How do I get the SQL query results into notepad?
This is a pretty old post, but it seems like you still need it.
If you have added a working button, then add the following to the ActionCanExecute function, of course renaming the ActionName to whatever you named your button action.
if ActionName = "UserDefinedActions.Requirements_ExportCSV" Then Set WSS = CreateObject("WScript.Shell") 'only needed if you're saving to Desktop DesktopFldr = WSS.SpecialFolders("Desktop") 'only needed if you're saving to Desktop OutputFile = DesktopFldr & "\Sample.csv" Set FSO = CreateObject("Scripting.FileSystemObject") Set CSV = FSO.CreateTextFile(OutputFile, true) ' CSV.WriteLine("Sample,1,2,3") 'Write just one line at a time, usually inside a loop CSV.Write("Sample,1,2,3" & vbCRLF & "NewLine,4,5,6") 'Write an entire file in one shot, use vbCRLF between lines CSV.Close Set FSO = Nothing msgbox "should have created as " & OutputFile End if