Created
September 10, 2013 09:47
-
-
Save obstschale/6507233 to your computer and use it in GitHub Desktop.
From http://www.ozgrid.com/forum/showthread.php?t=76720 Excle Macro to export a range of cells into .csv file. I haven't tested it but it looks good. Anyhow I don't take any responsibility for this code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub CmdButton_Click() | |
On Error Goto CmdButton_Click_Error | |
' | |
' export Macro | |
Selection.Copy | |
'create new workbook | |
Workbooks.Add | |
' Paste into it | |
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ | |
:=False, Transpose:=False | |
Application.CutCopyMode = False | |
' Note I'm from the UK so my date format might be different - dd/mm/yyyy :) | |
Yearstr = Mid(Date, 7, 4) | |
Monthstr = Mid(Date, 4, 2) | |
Daystr = Mid(Date, 1, 2) | |
Datestr = Yearstr & "_" & Monthstr & "_" & Daystr | |
FilenameStr = "\" & Datestr & "CSVpaste.txt" | |
On Error Goto Cont 'Ignore error if file cannot be deleted | |
Kill [Path] & FilenameStr | |
Cont: | |
On Error Goto CmdButton_Click_Error | |
'Save workbook as csv text file | |
ActiveWorkbook.SaveAs Filename:= _ | |
[Path] & FilenameStr _ | |
, FileFormat:=xlCSV, CreateBackup:=False | |
'concatenate strings into Notepad string | |
Notepad = "notepad.exe " & [Path] & FilenameStr | |
Application.DisplayAlerts = False | |
ActiveWorkbook.Close | |
Application.DisplayAlerts = True | |
'start notepad with csv file | |
Shell Notepad, vbNormalFocus | |
Goto endit | |
CmdButton_Click_Error: | |
MsgBox ("Error-" & Error) | |
endit: | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment