Save Active Sheet Macro

TW80CJ5

New Member
Joined
Jan 25, 2019
Messages
2
Good Morning,


I have an excel workbook that has multiple tabs. Here is what I am trying to accomplish:


1. I would like a macro to save the current active sheet by its worksheet tab name: Some_Active_Sheet_Name2 or Some_Active_Sheet_Name3 or Some_Active_Sheet_Name4


2. I would like to reference a specific cell on Sheet1!A2 to properly name the file. For example if the data in Sheet1 A2 said "Orlando", then I would like the file named Orlando_Some_Active_Sheet_Name2 or Orlando_Some_Active_Sheet_Name3.


3. I would like the macro to copy the contents on the current active sheet and paste it into a text file and save automatically.






Here is what I have so far:






'Copy the contents of a worksheet, and save it as a new workbook as a .txt file
'
Sub Some_Active_Sheet_Name2()
Dim wbSource As Workbook
Dim wsSource As Worksheet
Dim wbDest As Workbook
Dim fName As String


'References
Set wbSource = ActiveWorkbook
Set wsSource = ThisWorkbook.Sheets("Some_Active_Sheet_Name2")
Set wsSource = ThisWorkbook.Sheets("Some_Active_Sheet_Name3")
Set wbDest = Workbooks.Add


'Copy range on original sheet
'Using usedrange can be risky and may return the wrong result.
wsSource.UsedRange.Copy


'Save in new workbook
wbDest.Worksheets(1).Cells(1, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False


'Get file name and location
fName = ThisWorkbook.Path & "\Some_Active_Sheet_Name2.txt"
fName = ThisWorkbook.Path & "\Some_Active_Sheet_Name3.txt"


'Save new tab delimited file
wbDest.SaveAs fName, xlText


wbDest.Close SaveChanges:=True


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Cross posted https://www.excelforum.com/excel-programming-vba-macros/1261746-save-active-sheet-macro.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Cross posted https://www.excelforum.com/excel-programming-vba-macros/1261746-save-active-sheet-macro.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

I am very sorry!!!

https://www.excelforum.com/excel-pr...1746-save-active-sheet-macro.html#post5051801
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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