Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Last active June 8, 2020 13:37
Show Gist options
  • Save bblanchon/f3ffd298e75f6796d476d609a728b729 to your computer and use it in GitHub Desktop.
Save bblanchon/f3ffd298e75f6796d476d609a728b729 to your computer and use it in GitHub Desktop.
Excel macro to export CSV for InDesign
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