I have a workbook with 9 sheets, all named.
I want to export 3 of these sheets and save as txt files
I want to determine the saved name to include TODAYS date
I want to save in same location as the workbook exists.
I tried recording macro and going through steps, but it means saved name and location is always the same. I create a new folder and workbook each day, so this means overwriting original file every time and in wrong days folder.
I found the following script which does save in same directory as workbook, but it saves all sheets and names them same as sheet name. I have tried using bits from each but constant run time errors and cant get it to work, woudl appreciate any suggestions?
I want to export 3 of these sheets and save as txt files
I want to determine the saved name to include TODAYS date
I want to save in same location as the workbook exists.
I tried recording macro and going through steps, but it means saved name and location is always the same. I create a new folder and workbook each day, so this means overwriting original file every time and in wrong days folder.
I found the following script which does save in same directory as workbook, but it saves all sheets and names them same as sheet name. I have tried using bits from each but constant run time errors and cant get it to work, woudl appreciate any suggestions?
VBA Code:
Sub Worksheets_to_txt() '<--Saves each worksheet as a text file with the same name
Dim ws As Worksheet
Dim relativePath As String
Dim answer As VbMsgBoxResult
relativePath = ActiveWorkbook.Path
answer = MsgBox("Are you sure you want to export worksheets?", vbYesNo, "Run Macro") '<--Pop up box to confirm export
If answer = vbYes Then
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
ws.Select
ws.Copy
ActiveWorkbook.SaveAs Filename:= _
relativePath & "\" & ws.Name & ".txt", _
FileFormat:=xlText, CreateBackup:=False
ActiveWorkbook.Close
ActiveWorkbook.Activate
Next
End If
End Sub