Save only one sheet from workbook as txt file

Status
Not open for further replies.

ChanL

Board Regular
Joined
Apr 8, 2021
Messages
65
Office Version
  1. 2019
Platform
  1. Windows
Currently i working with an excel reporting task, after copy paste data from sheet "source" to sheet "destination", i need to save only "destination" as txt file.
The code that i currently using is good, but the results not always consistent as sometime it will save the "source" into txt file instead of the "destination" file
this is the code that i am using :
VBA Code:
Sub savefile()

Range("A1").Select
ChDir sheets("Main").Cells(3,2).value
ActiveWorkbook.SavesAs filename:= _
Sheets("Main").Cells(3,2).value+"799EBS.txt",fileformat:=xltext, _
create backup=false

end sub

I tried to add "Sheets("destination")in front of "range("A1").select , but it always hit error 1004 : select method of range class failed
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Just activate the sheet you want to save before saving it, i.e.
Rich (BB code):
Sub savefile()

Range("A1").Select
ChDir sheets("Main").Cells(3,2).value
Sheets("destination").Activate
ActiveWorkbook.SavesAs filename:= _
Sheets("Main").Cells(3,2).value+"799EBS.txt",fileformat:=xltext, _
create backup=false

end sub
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,213,489
Messages
6,113,954
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top