Hey everyone!
I have written some VBA code in my workbook called "main.xlsm". In this workbook I have 2 data sheets called POS1 and POS2 that I want to export as TXT. I tried using the worksheet.SaveAs method (will paste the code below). However, a very strange problem occurs when I run the code. The name of the workbook goes from "main.xlsm" to "POS2.txt" (which is actually supposed to be one of the results of my sheet exports, not this whole workbook). For my work, I need the workbook name to stay the same after running my code. Any help would be greatly appreciated!!
EDIT: Just to clarify, I have tried the saveas fileformats 20 and 42 too, and still having the same problem.
I have written some VBA code in my workbook called "main.xlsm". In this workbook I have 2 data sheets called POS1 and POS2 that I want to export as TXT. I tried using the worksheet.SaveAs method (will paste the code below). However, a very strange problem occurs when I run the code. The name of the workbook goes from "main.xlsm" to "POS2.txt" (which is actually supposed to be one of the results of my sheet exports, not this whole workbook). For my work, I need the workbook name to stay the same after running my code. Any help would be greatly appreciated!!
VBA Code:
Sub savingTXT()
Dim p1 As Worksheet
Set p1 = ThisWorkbook.Sheets("POS1")
Dim p2 As Worksheet
Set p2 = ThisWorkbook.Sheets("POS1")
p1.SaveAs Filename:="E:\FARID\Excel\new\POS automation\POS1.txt", FileFormat:=-4158, CreateBackup:=False
p2.SaveAs Filename:="E:\FARID\Excel\new\POS automation\POS2.txt", FileFormat:=-4158, CreateBackup:=False
End Sub
EDIT: Just to clarify, I have tried the saveas fileformats 20 and 42 too, and still having the same problem.
Last edited by a moderator: