Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-14-2005, 12:14 PM
rroach rroach is offline
Registered User
 
Join Date: 14 Mar 2005
Posts: 21
rroach is becoming part of the community
still stuck: get filename from range

Please Register to Remove these Ads

I'm new at this. With much help from this forum I've almost finished a major timesaving macro for our lab. But stuck on following problem. I load a list of files that are in a worksheet and do a for-next loop on them,. Before closing each file I want to save it as an XLS file AND as a text file. I don't understand VBA syntax well enough to know how to get the filename for the filesave command.

My code now:
Sub File_Cut_Metrics()

Dim wbList As Workbook
Dim wbDest As Workbook
Dim rcell As Range

Set wbList = Workbooks.Open("G:\newlist2")
For Each rcell In wbList.Sheets(1).Range("A1").CurrentRegion.Columns(1).Cells
Set wbDest = Workbooks.Open(rcell.Value)

NB: If I put in "Msgbox rcell" here it shows the correct filename

do some stuff

wbDest.Save

wbDest.SaveAs Filename:=rcell, FileFormat:=xlText, CreateBackup:=False
NOTE: sub'ing rcell.value for rcell above doesn't work either


wbDest.Close savechanges:=False
Next

End Sub

What do I need to change to send the right filename to the SaveAs statement?

TIA,

Rob

Last edited by rroach; 07-14-2005 at 12:22 PM.
Reply With Quote
  #2  
Old 07-14-2005, 02:05 PM
Bernie Deitrick
Guest
 
Posts: n/a
Re: still stuck: get filename from range

Rob,

Do your file names on the sheet have .xls at the end?

Perhaps:

Wbdest.SaveAs Filename:=Substitute(RCell.Value, ".xls", ".txt"), FileFormat:=xlText

HTH,
Bernie
MS Excel MVP


"rroach" <rroach.1s65v7_1121360843.7756@excelforum-nospam.com> wrote in message
news:rroach.1s65v7_1121360843.7756@excelforum-nospam.com...
>
> I'm new at this. With much help from this forum I've almost finished a
> major timesaving macro for our lab. But stuck on following problem. I
> load a list of files that are in a worksheet and do a for-next loop on
> them,. Before closing each file I want to save it as an XLS file AND as
> a text file. I don't understand VBA syntax well enough to know how to
> get the filename for the filesave command.
>
> My code now:
> Sub File_Cut_Metrics()
>
> Dim wbList As Workbook
> Dim wbDest As Workbook
> Dim rcell As Range
>
> Set wbList = Workbooks.Open("G:\newlist2")
> For Each rcell In
> wbList.Sheets(1).Range("A1").CurrentRegion.Columns(1).Cells
> Set wbDest = Workbooks.Open(rcell.Value)
>
> NB: IF I PUT IN \"MSGBOX RCELL\" HERE IT SHOWS THE CORRECT FILENAME
>
> do some stuff
>
> wbDest.Save
>
> WBDEST.SAVEAS FILENAME:=RCELL, FILEFORMAT:=XLTEXT, CREATEBACKUP:=FALSE
> NOTE: SUB'ING RCELL.VALUE FOR RCELL ABOVE DOESN'T WORK EITHER
>
> wbDest.Close savechanges:=False
> Next
>
> End Sub
>
> What do I need to change to send the right filename to the SaveAs
> statement?
>
> TIA,
>
> Rob
>
>
> --
> rroach
> ------------------------------------------------------------------------
> rroach's Profile: http://www.excelforum.com/member.php...o&userid=21093
> View this thread: http://www.excelforum.com/showthread...hreadid=387227
>



Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump