Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Give a sheet a name from data in a cell-saving to a specific folde

I have a blank worksheet (call it no name) and want to use the data in cell
E11 (e.g.data could be 18208C) to rename the worksheet (eg to 18208C)

I then want to save the workbook with the same name as the new worksheet's
name (ie as an example still 18208C) in a subfolder of a Folder called Jobs
on my C drive.

The proviso is that the subfolder name within the Jobs Folder is always the
first 3 digits of a workbook name & if the Subfolder Name (ie in this example
182) within the Jobs Folder doesn't already exist I need to create a new one
using those three digits before saving the workbook
Thanks again
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Give a sheet a name from data in a cell-saving to a specific folde

Hi Chris

Try the below and feedback..(untested)

Sub Macro()
Dim strName As String
Dim strPath As String
Dim strFolder As String
Dim blnExist As Boolean

blnExist = False
strName = Left(Trim(Range("E11")), 3)
strPath = "c:\Jobs\"
strFolder = Dir(strPath & strName & "*", vbDirectory)
Do While strFolder < ""
If (GetAttr(strPath & strFolder) And vbDirectory) = vbDirectory Then
blnExist = True: Exit Do
End If
strFolder = Dir()
Loop
If blnExist = False Then MkDir "c:\jobs\" & strName
ActiveSheet.Name = Trim(Range("E11"))
ActiveWorkbook.SaveAs "c:\jobs\" & strName & "\" & Trim(Range("E11")) & "xls"
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Chris Maddogz" wrote:

I have a blank worksheet (call it no name) and want to use the data in cell
E11 (e.g.data could be 18208C) to rename the worksheet (eg to 18208C)

I then want to save the workbook with the same name as the new worksheet's
name (ie as an example still 18208C) in a subfolder of a Folder called Jobs
on my C drive.

The proviso is that the subfolder name within the Jobs Folder is always the
first 3 digits of a workbook name & if the Subfolder Name (ie in this example
182) within the Jobs Folder doesn't already exist I need to create a new one
using those three digits before saving the workbook
Thanks again

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Give a sheet a name from data in a cell-saving to a specific folde

Chris, Initially I thought your subfolder names starts with the first 3
digits and hence the loop...You dont need to loop...instead try the below

Sub Macro()
Dim strName As String
Dim strPath As String
Dim strFolder As String

strName = Left(Trim(Range("E11")), 3)
strPath = "c:\Jobs\"
If Dir(strPath & strName, vbDirectory) = "" Then
MkDir "c:\jobs\" & strName
End If
ActiveSheet.Name = Trim(Range("E11"))
ActiveWorkbook.SaveAs "c:\jobs\" & strName & "\" & Trim(Range("E11")) & ".xls"
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Chris Maddogz" wrote:

I have a blank worksheet (call it no name) and want to use the data in cell
E11 (e.g.data could be 18208C) to rename the worksheet (eg to 18208C)

I then want to save the workbook with the same name as the new worksheet's
name (ie as an example still 18208C) in a subfolder of a Folder called Jobs
on my C drive.

The proviso is that the subfolder name within the Jobs Folder is always the
first 3 digits of a workbook name & if the Subfolder Name (ie in this example
182) within the Jobs Folder doesn't already exist I need to create a new one
using those three digits before saving the workbook
Thanks again

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Give a sheet a name from data in a cell-saving to a specific f

They both worked a treat certainly saved a lot of manual save as etc.

"Jacob Skaria" wrote:

Chris, Initially I thought your subfolder names starts with the first 3
digits and hence the loop...You dont need to loop...instead try the below

Sub Macro()
Dim strName As String
Dim strPath As String
Dim strFolder As String

strName = Left(Trim(Range("E11")), 3)
strPath = "c:\Jobs\"
If Dir(strPath & strName, vbDirectory) = "" Then
MkDir "c:\jobs\" & strName
End If
ActiveSheet.Name = Trim(Range("E11"))
ActiveWorkbook.SaveAs "c:\jobs\" & strName & "\" & Trim(Range("E11")) & ".xls"
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Chris Maddogz" wrote:

I have a blank worksheet (call it no name) and want to use the data in cell
E11 (e.g.data could be 18208C) to rename the worksheet (eg to 18208C)

I then want to save the workbook with the same name as the new worksheet's
name (ie as an example still 18208C) in a subfolder of a Folder called Jobs
on my C drive.

The proviso is that the subfolder name within the Jobs Folder is always the
first 3 digits of a workbook name & if the Subfolder Name (ie in this example
182) within the Jobs Folder doesn't already exist I need to create a new one
using those three digits before saving the workbook
Thanks again

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can DSUM give me specific data? evergreenstar Excel Discussion (Misc queries) 1 January 4th 10 10:44 PM
Give a sheet name from a Cell Hardeep Kanwar Excel Worksheet Functions 5 July 20th 09 08:41 AM
How to position to a specific sheet before saving Pete Kipe Excel Programming 2 December 17th 07 07:30 PM
How to get specific cell data from one sheet! Paul Excel Programming 9 August 25th 07 03:30 PM
Send data from userform to specific cell on specific sheet? JennLee Excel Programming 10 March 10th 07 02:55 AM


All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"