I want two sheets of my Excel workbook to be saved as txt file. The name of the file is compiled of a fixed part ("TrialList" or "BlockList") and two values from another sheet (subject and session number):
Sheets("TrialList").Select
Dim part1 As String
Dim part2 As String
part1 = Range("O2").Value 'subject number
part2 = Range("P2").Value 'session number
Sheets("txt").Select
Cells.Select
ActiveWorkbook.SaveAs Filename:= _
"C:\...\TrialList " & part1 & "-" & part2 & ".txt", FileFormat:= _
xlText, CreateBackup:=False
Sheets("BlockList").Select
Cells.Select
ActiveWorkbook.SaveAs Filename:= _
"C:\...\BlockList " & part1 & "-" & part2 & ".txt", FileFormat:= _
xlText, CreateBackup:=False
Now, saving the text files with the desired file names works perfectly. However, Excel decides to change the names of the sheets that have been saved as text files accordingly. This is something I want to prevent from happening, since a second loop of actions will end because of the unexpected sheet names... How do I work around this autonomous behaviour of Excel?
Bookmarks