Save inactive worksheet as text file using active worksheet cell for filename

I have an excel workbook consisting of 2 sheets.
Sheet 1 = Entry
Sheet 2 = Compiled
What I'd like to have happen is to have a macro to save a copy of the Compiled sheet as a text file with a filename identified in Sheet1 cell  C2.

The end result being a text copy of the Compiled sheet saved with a button click so I can continue working on the Entry form to create yet another. I've tried several variants on this theme on here and google found, but I lack the ability to modify it enough to meet my need so am hoping for help.

Thanks!
K_R_MAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
For example:
Sub SaveTextCopy()
   Dim wks As Worksheet
   Set wks = Worksheets("Compiled")
   wks.SaveAs Sheets("Entry").Range("C2").Value & ".txt", xlTextWindows
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
K_R_MAuthor Commented:
Works perfectly, thank you very much. I can clearly see where I was mistaken now. As a brief follow up question, how can I better define the directory I wish to save to? My attempt below fails

 
Sub SaveTextCopy()
   Dim wks As Worksheet
   Dim path As String
   path = "C:\Flags\"
   Set wks = Worksheets("Compiled")
   wks.SaveAs path & Sheets("Entry").Range("C2").Value & ".txt", xlTextWindows
End Sub 

Open in new window


0
Rory ArchibaldCommented:
Fails in what way?
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

K_R_MAuthor Commented:
Okay, Once I run the macro, the filename that I am working on and the Compiled sheet itself, changes to the Cell C2 name and causes the macro to fail on the next attempt. Is there a save as copy method so that the original file is unchanged?
0
Rory ArchibaldCommented:
No - there is a SaveCopyAs method, but that is for the workbook. You can do this though:
Sub SaveTextCopy()  
   Dim wks As Worksheet  
   Dim path As String  
   path = "C:\Flags\"  
   Set wks = Worksheets("Compiled")
   wks.Copy
   activeworkbook.SaveAs path & thisworkbook.Sheets("Entry").Range("C2").Value & ".txt", xlTextWindows
   activeworkbook.close false
End Sub 

Open in new window

0
K_R_MAuthor Commented:
That did the trick, original file is intact, new text file is where it belongs. Thanks again, very well done!
0
Rory ArchibaldCommented:
Just to tidy up a bit:
Sub SaveTextCopy()   
   Dim wks As Worksheet   
   Dim path As String   
Application.ScreenUpdating = False
   path = "C:\Flags\"   
   Set wks = Worksheets("Compiled") 
   wks.Copy 
   activeworkbook.SaveAs path & thisworkbook.Sheets("Entry").Range("C2").Value & ".txt", xlTextWindows 
   activeworkbook.close false 
Application.ScreenUpdating = True
End Sub 

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.