Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Export_Click()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim MyPath As String
- Dim MyFileName As String
- 'The path and file names:
- MyPath = ActiveWorkbook.Path & "Uploads"
- MyFileName = "" & Range("a2") & "_Upload"
- On Error GoTo Ending
- 'Makes sure the path name ends with "":
- If Not Right(MyPath, 1) = "" Then MyPath = MyPath & ""
- 'Makes sure the filename ends with ".csv"
- If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
- 'Copies the sheet to a new workbook:
- Sheets("UploadData").Copy
- 'The new workbook becomes Activeworkbook:
- With ActiveWorkbook 'Saves the new workbook to given folder / filename:
- .SaveAs FileName:= _
- MyPath & MyFileName, _
- FileFormat:=xlCSV, _
- CreateBackup:=False 'Closes the file
- .Close False
- End With
- ChDir MyPath
- Workbooks.Open FileName:= _
- MyPath & "" & MyFileName & """"
- ActiveWorkbook.Save
- ActiveWorkbook.Close
- GoTo Skip
- Ending:
- MsgBox ("ERROR! Please make sure you have a folder named Uploads next to the template file")
- ActiveWorkbook.Close
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- Skip:
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement