Save only one sheet from workbook as txt file

Status
Not open for further replies.

ChanL

New Member
Joined
Apr 8, 2021
Messages
12
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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,934
Office Version
  1. 365
Platform
  1. Windows
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
 
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,129,713
Messages
5,637,926
Members
416,993
Latest member
ant8989

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
Top