Hi all!
I've got a workbook with a macro that will export my various tabs, each as separate CSV files, and save them into a specified folder. The problem I'm having is that the files get saved with a blank line at the end. In order to use the files in another system, I have to open each one in a notepad editor, delete the line, and then save the file. I'm 100% sure something like this could be automated or fixed, but I'm 0% sure how to do it... can anyone help?
My macro is below (with some edits to protect confidential information ).
Thank you!!!!!!!
I've got a workbook with a macro that will export my various tabs, each as separate CSV files, and save them into a specified folder. The problem I'm having is that the files get saved with a blank line at the end. In order to use the files in another system, I have to open each one in a notepad editor, delete the line, and then save the file. I'm 100% sure something like this could be automated or fixed, but I'm 0% sure how to do it... can anyone help?
My macro is below (with some edits to protect confidential information ).
Thank you!!!!!!!
VBA Code:
Sub ExportCSVs()
'Prevent the screen from flickering and speed up code.
Application.ScreenUpdating = False
'Yes/No Box to make sure the user wants to run the macro.
CarryOn = MsgBox("Do you want to export CSV files?" & vbCrLf & "This will also save your workbook.", vbYesNo, "Export CSV Test Files")
If CarryOn = vbYes Then
'Yes/No Box For Importing Resources
CarryOn = MsgBox("Do you want to import the latest export file?", vbYesNo, "Import Latest Export?")
If CarryOn = vbNo Then
GoTo Skip_Resources
End If
'Settings to get started and enable functions further down.
Dim Sht As Worksheet
Dim ThisSheet As Worksheet
Set ThisSheet = ActiveSheet
Dim sourceworkbook As Workbook
Dim currentworkbook As Workbook
'Prevents Dialogue Boxes
Application.DisplayAlerts = False
'Import Latest Export File
Call ImportCSVExport.ImportDatafromotherworksheet
'Prevent the screen from flickering and speed up code. This is needed again if the user clicks yes to import the Taxonomy export.
Application.ScreenUpdating = False
Skip_Resources:
'Enable dialogue boxes
Application.DisplayAlerts = True
'More settings to get enable functions
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FolderName As String
Set xWb = Application.ThisWorkbook
'Setting up and creating the folder with time-date stamp in the name
DateString = Format(Now, "mm-dd-yyyy hh-mm-ss")
FolderName = xWb.Path & "\" & "UAT Import Files " & DateString
MkDir FolderName
'Actual saving of worksheets as separate CSV files
''Skip specific worksheets
For Each xWs In xWb.Worksheets
On Error Resume Next
If (xWs.Name <> "Summary") And (xWs.Name <> "Export") And (xWs.Name <> "UAT Record") Then
xWs.Copy
FileExtStr = ".csv": FileFormatNum = 6
'Save the test cases inside the folder and use the tab name for the file name
xFile = FolderName & "\" & Application.ActiveWorkbook.Sheets(1).Name & FileExtStr
Application.ActiveWorkbook.SaveAs xFile, FileFormat:=FileFormatNum
Application.ActiveWorkbook.Close False
End If
Next xWs
'Turn screen updating back on for Excel
Application.ScreenUpdating = True
'Go back to the "Summary" worksheet and clear some memory
ThisWorkbook.Sheets("Summary").Activate
ThisWorkbook.Sheets("Summary").Range("A1").Select
ThisSheet.Select
Set ThisSheet = Nothing
'Yes/No box asking if the folder should open with the new files
CarryOn = MsgBox("Import Files Are Finished Processing" & vbNewLine & "Do you want to view the files?", vbYesNo, "Test Cases Are Finished")
If CarryOn = vbYes Then
Dim source_folder_name As String
source_folder_name = FolderName
ActiveWorkbook.FollowHyperlink Address:=source_folder_name, NewWindow:=True
End If
End If
'Save Workbook
ActiveWorkbook.Save
End Sub