Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

saving a worksheet with the name read from a text file

  Asked By: Hayrah    Date: Feb 22    Category: MS Office    Views: 840
  

Can some one provide me with a little piece of VBA code that can
read data from a text file(.txt extensionalong with directory name) and save the
worksheet with the same name at the same path and with same extension.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Marta Kim     Answered On: Feb 22

we could use a little clarification, or we'll have to make assumptions... which
is not good
First.
Are you wanting to save  the workBOOK or a SHEET of the workbook
(which is, what you called, a "worksheet")

Second,
"save the worksheet": Do you mean that you want to save the CURRENT workbook
(the one in which this code  is running) as a new name supplied in the text  file?

Third,
What does the content of the text file  look like?
Simplest: it contains only the complete file name (including path) for the
Excel workbook
More complex: within the file, there is a string that says, for instance,
"filename:"
followed by the name to use for the workbook. Use alternate path  hard-coded
into the
macro.

Fourth,
Does the phrase "with the same name at the same path and with the same
extension" mean
that the text file has the full path and file name that you want to use for the
workbook?
or does "same" mean the "same" as the workbook that contains the macro you're
running?
also... "same extension": does that mean that there is a possibility that
you're going to be trying
to save the "current" excel file as another file format (xlt, txt, csv, etc)
based on what the file
name is in the text file?

Fifth,
IF, you're saving  the current Excel file as a new name (name obtained from the
text file)
Do you want the currently opened file to be the NEW file or the ORIGINAL file?
Let say your macro is written in a file called MacroMaster.xls
The macro opens the text file, reads the first line and determines that the new
file is to be called
NewFile.xls
If you use the SaveAs method, then the new file is created, and the file that is
currently open
on the screen is the new file.
However, if you use the SaveCopyAs method, the new file is created, but the file
that is open
remains the MacroMaster file...

So.. as you can see, even though your question sounds simple, there are many
considerations to
be..er..considered!

I'd be glad to throw something together for you if you'll give me some
additional data...

 
Didn't find what you were looking for? Find more on saving a worksheet with the name read from a text file Or get search suggestion and latest updates.




Tagged: