Automatic Sheet Name Read and Rename

  • Thread starter Thread starter DataMan
  • Start date Start date
D

DataMan

I need to know if there is a way to write a macro or the code that will
open a file with the one worksheet that has a variable name and rename
it to "Data".

A program we pull trends with creates a .csv file with the worksheet
that has the same name as the file name. I am trying to create a macro
that will chart the data in the file. I want to be able to share this
and would like to not have to constrict file names to match a
referenced sheet name in a macro. I would rather rename the sheet when
the file opens to match my referenced sheet name in my macro.

Can this be done? Please answer this one. The last message I submitted
has never been answered. That was over 2 months ago. Nobody would find
it now.
 
Add these two lines of code to your macro right after opening the .csv file in you code.

****Assuming the file opens with only one tab****
activeTab = ActiveSheet.Name
Sheets(activeTab).Name = "Data"





----- DataMan > wrote: -----

I need to know if there is a way to write a macro or the code that will
open a file with the one worksheet that has a variable name and rename
it to "Data".

A program we pull trends with creates a .csv file with the worksheet
that has the same name as the file name. I am trying to create a macro
that will chart the data in the file. I want to be able to share this
and would like to not have to constrict file names to match a
referenced sheet name in a macro. I would rather rename the sheet when
the file opens to match my referenced sheet name in my macro.

Can this be done? Please answer this one. The last message I submitted
has never been answered. That was over 2 months ago. Nobody would find
it now.
 
You could do:

worksheets(1).name = "data"

But since there's only one worksheet in the workbook, couldn't your macro just
refer to worksheets(1)?

(might not work when the user adds a second sheet, though.)
 
Thanks for all your help. I used the first bit of code. It is just what
I needed.

DataMan
 
Back
Top