Last active
June 8, 2020 13:37
-
-
Save bblanchon/f3ffd298e75f6796d476d609a728b729 to your computer and use it in GitHub Desktop.
Excel macro to export CSV for InDesign
This file contains hidden or 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 InDesignExport() | |
Dim csvFilename As String | |
Dim transpose As Boolean | |
csvFilename = Mid(ActiveWorkbook.FullName, 1, InStrRev(ActiveWorkbook.FullName, ".")) & "txt" | |
Range("A1").Select | |
Range(Selection, Selection.End(xlDown)).Select | |
Range(Selection, Selection.End(xlToRight)).Select | |
transpose = Selection.Rows.Count > Selection.Columns.Count | |
Selection.Copy | |
Workbooks.Add | |
Selection.PasteSpecial Paste:=xlPasteValues, transpose:=transpose | |
Application.CutCopyMode = False | |
ActiveSheet.Cells.Replace What:=Chr(10), Replacement:=" " | |
Application.DisplayAlerts = False 'Possibly overwrite without asking | |
ActiveWorkbook.SaveAs Filename:=csvFilename, FileFormat:=xlUnicodeText, CreateBackup:=False | |
ActiveWindow.Close | |
Application.DisplayAlerts = True | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment