PC Review


Reply
Thread Tools Rate Thread

Change file name - remove specific text

 
 
cgilmartin@gmail.com
Guest
Posts: n/a
 
      6th Oct 2006
Newbie, so please be gentle...

I have a macro that runs a macro across multiple CSV files in a folder,
makes formating changes, then renames the file (adds "_ADS"), converts
it to an XLS and saves to a different directory. Everything works
great, except that in keeping the workbook name, it keeps the .csv in
the file name (example filename.csv.xls. This can sometimes exceed the
31 limit. Here's the renaming, converting and saving code:


Sheets("Sheet2").Name = ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:="C:\Documents and
Settings\User\Desktop\Ads\" & ActiveWorkbook.Name & "_ADS" & ".xls", _
FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
CreateBackup:=False


Is there a way to remove the ".csv" from the workbook name during
renaming, converting?

sorry if this is basic, but I am just getting started with macros.

Thanks,
Chris

 
Reply With Quote
 
 
 
 
Sandy
Guest
Posts: n/a
 
      6th Oct 2006
Try this out - used Left and Len to remove the last 4 characters of
"ActiveWorkbook.Name"

Sheets("Sheet2").Name = ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\User\Desktop\Ads\" & _
Left(ActiveWorkbook.Name, (Len(ActiveWorkbook.Name) - 4)) & _
"_ADS" & ".xls", FileFormat:=xlWorkbookNormal, _
ReadOnlyRecommended:=False, CreateBackup:=False

Sandy


(E-Mail Removed) wrote:
> Newbie, so please be gentle...
>
> I have a macro that runs a macro across multiple CSV files in a folder,
> makes formating changes, then renames the file (adds "_ADS"), converts
> it to an XLS and saves to a different directory. Everything works
> great, except that in keeping the workbook name, it keeps the .csv in
> the file name (example filename.csv.xls. This can sometimes exceed the
> 31 limit. Here's the renaming, converting and saving code:
>
>
> Sheets("Sheet2").Name = ActiveWorkbook.Name
> ActiveWorkbook.SaveAs Filename:="C:\Documents and
> Settings\User\Desktop\Ads\" & ActiveWorkbook.Name & "_ADS" & ".xls", _
> FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
> CreateBackup:=False
>
>
> Is there a way to remove the ".csv" from the workbook name during
> renaming, converting?
>
> sorry if this is basic, but I am just getting started with macros.
>
> Thanks,
> Chris


 
Reply With Quote
 
=?Utf-8?B?SGFsaW0=?=
Guest
Posts: n/a
 
      7th Oct 2006
Hi Martin,

Just adding some...
Or you can use this :

Dim WBNAME as string

WBNAME = Replace(ActiveWorkbook.Name,".csv" ,"")

Sheets("Sheet2").Name = ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:="C:\Documents and
Settings\User\Desktop\Ads\" & WBNAME & "_ADS" & ".xls", _
FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
CreateBackup:=False


--

Regards,

Halim


"(E-Mail Removed)" wrote:

> Newbie, so please be gentle...
>
> I have a macro that runs a macro across multiple CSV files in a folder,
> makes formating changes, then renames the file (adds "_ADS"), converts
> it to an XLS and saves to a different directory. Everything works
> great, except that in keeping the workbook name, it keeps the .csv in
> the file name (example filename.csv.xls. This can sometimes exceed the
> 31 limit. Here's the renaming, converting and saving code:
>
>
> Sheets("Sheet2").Name = ActiveWorkbook.Name
> ActiveWorkbook.SaveAs Filename:="C:\Documents and
> Settings\User\Desktop\Ads\" & ActiveWorkbook.Name & "_ADS" & ".xls", _
> FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
> CreateBackup:=False
>
>
> Is there a way to remove the ".csv" from the workbook name during
> renaming, converting?
>
> sorry if this is basic, but I am just getting started with macros.
>
> Thanks,
> Chris
>
>

 
Reply With Quote
 
CG
Guest
Posts: n/a
 
      9th Oct 2006
Thank you both. Both options worked!

CG

Halim wrote:
> Hi Martin,
>
> Just adding some...
> Or you can use this :
>
> Dim WBNAME as string
>
> WBNAME = Replace(ActiveWorkbook.Name,".csv" ,"")
>
> Sheets("Sheet2").Name = ActiveWorkbook.Name
> ActiveWorkbook.SaveAs Filename:="C:\Documents and
> Settings\User\Desktop\Ads\" & WBNAME & "_ADS" & ".xls", _
> FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
> CreateBackup:=False
>
>
> --
>
> Regards,
>
> Halim
>
>
> "(E-Mail Removed)" wrote:
>
> > Newbie, so please be gentle...
> >
> > I have a macro that runs a macro across multiple CSV files in a folder,
> > makes formating changes, then renames the file (adds "_ADS"), converts
> > it to an XLS and saves to a different directory. Everything works
> > great, except that in keeping the workbook name, it keeps the .csv in
> > the file name (example filename.csv.xls. This can sometimes exceed the
> > 31 limit. Here's the renaming, converting and saving code:
> >
> >
> > Sheets("Sheet2").Name = ActiveWorkbook.Name
> > ActiveWorkbook.SaveAs Filename:="C:\Documents and
> > Settings\User\Desktop\Ads\" & ActiveWorkbook.Name & "_ADS" & ".xls", _
> > FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
> > CreateBackup:=False
> >
> >
> > Is there a way to remove the ".csv" from the workbook name during
> > renaming, converting?
> >
> > sorry if this is basic, but I am just getting started with macros.
> >
> > Thanks,
> > Chris
> >
> >


 
Reply With Quote
 
CG
Guest
Posts: n/a
 
      9th Oct 2006
One more question...

Is there a way to only run code that shortens the name if the name is
31 (or more) characters? I would like to maintain those files that do
not exceed the limit, only changing those that do.

Thanks!


CG wrote:
> Thank you both. Both options worked!
>
> CG
>
> Halim wrote:
> > Hi Martin,
> >
> > Just adding some...
> > Or you can use this :
> >
> > Dim WBNAME as string
> >
> > WBNAME = Replace(ActiveWorkbook.Name,".csv" ,"")
> >
> > Sheets("Sheet2").Name = ActiveWorkbook.Name
> > ActiveWorkbook.SaveAs Filename:="C:\Documents and
> > Settings\User\Desktop\Ads\" & WBNAME & "_ADS" & ".xls", _
> > FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
> > CreateBackup:=False
> >
> >
> > --
> >
> > Regards,
> >
> > Halim
> >
> >
> > "(E-Mail Removed)" wrote:
> >
> > > Newbie, so please be gentle...
> > >
> > > I have a macro that runs a macro across multiple CSV files in a folder,
> > > makes formating changes, then renames the file (adds "_ADS"), converts
> > > it to an XLS and saves to a different directory. Everything works
> > > great, except that in keeping the workbook name, it keeps the .csv in
> > > the file name (example filename.csv.xls. This can sometimes exceed the
> > > 31 limit. Here's the renaming, converting and saving code:
> > >
> > >
> > > Sheets("Sheet2").Name = ActiveWorkbook.Name
> > > ActiveWorkbook.SaveAs Filename:="C:\Documents and
> > > Settings\User\Desktop\Ads\" & ActiveWorkbook.Name & "_ADS" & ".xls", _
> > > FileFormat:=xlWorkbookNormal, ReadOnlyRecommended:=False, _
> > > CreateBackup:=False
> > >
> > >
> > > Is there a way to remove the ".csv" from the workbook name during
> > > renaming, converting?
> > >
> > > sorry if this is basic, but I am just getting started with macros.
> > >
> > > Thanks,
> > > Chris
> > >
> > >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to remove text in specific place Scott Microsoft Excel Worksheet Functions 4 6th Oct 2008 07:19 PM
Remove Specific Text/Character in Specific Place Gary Dolliver Microsoft Access Queries 7 19th Dec 2007 10:13 PM
Change the color of text at a specific location on each text line =?Utf-8?B?QnJpYW4gQ29vaw==?= Microsoft C# .NET 7 26th Sep 2007 02:14 PM
how to remove specific characters from a text field =?Utf-8?B?U3VwZXJkNzA3?= Microsoft Access VBA Modules 3 24th Apr 2007 04:23 AM
Remove Specific Text - HELP! LastHair Microsoft Excel Worksheet Functions 6 19th Jul 2006 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:28 PM.