Skip to content

Instantly share code, notes, and snippets.

@stevehenderson
Last active December 17, 2015 08:39
Show Gist options
  • Save stevehenderson/5581467 to your computer and use it in GitHub Desktop.
Save stevehenderson/5581467 to your computer and use it in GitHub Desktop.
VBA code for saving a csv to disk
Sub SendResults()
Dim OutApp As Object
Dim OutMail As Object
Dim currentPath As String
currentPath = Application.ActiveWorkbook.Path
currentPath = "\\se\ABETWorking\SEN0_CapstoneDA"
Dim csvPath As String
Dim emailBody As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
csvPath = currentPath & "\results_" & Worksheets("MAIN").Range("A2") & ".csv"
emailBody = writeCSV(csvPath)
If emailBody <> "Error" Then
MsgBox ("Thank you for your assessment. It was saved to " & csvPath & vbNewLine & vbNewLine & "Please save a copy of this file for your records.")
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Exit Sub
ErrHandler:
MsgBox ("There was an error saving your assessment. Please save a copy of this file and email to LTC Henderson.")
' error handling code
Resume Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment