Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default Save Filename

Hello All,

I have a workbook that has a heap of pages.
It is broken down into sheet names:
1-30 (visible)
1-30-Dock (hidden)
1-30-Delivery (hidden)
1-30-Admin (hidden)

Then continues onto the next set of four sheets, 31-60 etc.
The data from the visible sheet is copied onto the other 3 sheets.
Any sheets that are not used are deleted auto on exit, with the rest being
saved to a single file.
What I need to know is...can i save a new workbook that only contains the
visible sheets, then another with only the Dock sheets etc etc.
The number of sheets used each time varies widely. But if the visible sheet
is not used, then neither are the other 3 in the set

Confused...try being in my seat =)

Regards
Peter

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Save Filename

You can call this with which group you want to save. for example

Option Explicit
Sub Savesheet
CopySheets ' type 1-30 sheets
CopySheets "Dock"
CopySheets "Delivery"
CopySehets "Admin"
End Sub



Sub CopySheets(Optional searchString As Variant)
Dim s As String
Dim varr As Variant
Dim sh As Worksheet
Dim shts As Worksheets
Dim icnt As Long
Dim lastrow
ReDim varr(0 To 0)
For Each sh In ActiveWorkbook.Worksheets
If IsMissing(searchString) Then
icnt = InStr(1, sh.Name, "dock", vbTextCompare)
icnt = icnt + InStr(1, sh.Name, "delivery", vbTextCompare)
icnt = icnt + InStr(1, sh.Name, "admin", vbTextCompare)


' you could change the test to visible sheets rather than
' excluding other types. -if sh.visible = xlSheetVisible then <-
' rather than -If icnt = 0 then<-
If icnt = 0 Then
lastrow = sh.Cells(Rows.Count, 1).End(xlUp).Row
If lastrow 2 Then
varr(UBound(varr)) = sh.Name
ReDim Preserve varr(0 To UBound(varr) + 1)
End If
End If
Else
If InStr(1, sh.Name, searchString, vbTextCompare) 0 Then
lastrow = sh.Cells(Rows.Count, 1).End(xlUp).Row
If lastrow 2 Then
varr(UBound(varr)) = sh.Name
ReDim Preserve varr(0 To UBound(varr) + 1)
End If
End If
End If
Next
If Not IsEmpty(varr(0)) Then
ReDim Preserve varr(0 To UBound(varr) - 1)
If IsMissing(searchString) Then
Worksheets(varr).Copy
ActiveWorkbook.SaveAs "NumberedSheets.xls"
ActiveWorkbook.Close SaveChanges:=False
Else
Set shts = Worksheets(varr)
For Each sh In shts
sh.Visible = xlVisible
Next
sh.Copy
ActiveWorkbook.SaveAs searchString & ".xls"
ActiveWorkbook.Close SaveChanges:=False
For Each sh In shts
sh.Visible = xlSheetHidden
Next
End If
End If
End Sub

I don't know what your sheets look like, so I put in a check - if there is
anything beyond row 2, then they are not empty. Adjust that check to match
your criteria.

Code is untested, so there may be typos or logic errors, but it should give
you some ideas.
--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Hello All,

I have a workbook that has a heap of pages.
It is broken down into sheet names:
1-30 (visible)
1-30-Dock (hidden)
1-30-Delivery (hidden)
1-30-Admin (hidden)

Then continues onto the next set of four sheets, 31-60 etc.
The data from the visible sheet is copied onto the other 3 sheets.
Any sheets that are not used are deleted auto on exit, with the rest being
saved to a single file.
What I need to know is...can i save a new workbook that only contains the
visible sheets, then another with only the Dock sheets etc etc.
The number of sheets used each time varies widely. But if the visible

sheet
is not used, then neither are the other 3 in the set

Confused...try being in my seat =)

Regards
Peter



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Save Filename

Hi Peter,

try using a loop connected with the worksheet.visible
function as follows:

For Each Worksheet In Workbooks("abcd.xls")

If Worksheet.Visible = True Then
Worksheet.Copy
Workbooks("localcopyvisible.xls").Activate
Worksheet.Paste
Else
Worksheet.Copy
Workbooks("localcopyhidden.xls").Activate
Worksheet.Paste
End If

Next Worksheet


Sorry for double-Posting, missed some code ;o)

Best

Markus


-----Original Message-----
Hello All,

I have a workbook that has a heap of pages.
It is broken down into sheet names:
1-30 (visible)
1-30-Dock (hidden)
1-30-Delivery (hidden)
1-30-Admin (hidden)

Then continues onto the next set of four sheets, 31-60

etc.
The data from the visible sheet is copied onto the other

3 sheets.
Any sheets that are not used are deleted auto on exit,

with the rest being
saved to a single file.
What I need to know is...can i save a new workbook that

only contains the
visible sheets, then another with only the Dock sheets

etc etc.
The number of sheets used each time varies widely. But if

the visible sheet
is not used, then neither are the other 3 in the set

Confused...try being in my seat =)

Regards
Peter

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default Save Filename

Thanks Tom and Markus
I'll have a test run and see if more valium are needed, and the psych needs
a third session for this week.

Regards
Peter


"Markus Scheible" wrote:

Hi Peter,

try using a loop connected with the worksheet.visible
function as follows:

For Each Worksheet In Workbooks("abcd.xls")

If Worksheet.Visible = True Then
Worksheet.Copy
Workbooks("localcopyvisible.xls").Activate
Worksheet.Paste
Else
Worksheet.Copy
Workbooks("localcopyhidden.xls").Activate
Worksheet.Paste
End If

Next Worksheet


Sorry for double-Posting, missed some code ;o)

Best

Markus


-----Original Message-----
Hello All,

I have a workbook that has a heap of pages.
It is broken down into sheet names:
1-30 (visible)
1-30-Dock (hidden)
1-30-Delivery (hidden)
1-30-Admin (hidden)

Then continues onto the next set of four sheets, 31-60

etc.
The data from the visible sheet is copied onto the other

3 sheets.
Any sheets that are not used are deleted auto on exit,

with the rest being
saved to a single file.
What I need to know is...can i save a new workbook that

only contains the
visible sheets, then another with only the Dock sheets

etc etc.
The number of sheets used each time varies widely. But if

the visible sheet
is not used, then neither are the other 3 in the set

Confused...try being in my seat =)

Regards
Peter

.


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
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
Save as .htm with filename from cell galimi Excel Discussion (Misc queries) 1 May 13th 05 04:51 AM
save as filename Geo Siggy[_14_] Excel Programming 3 April 6th 04 01:26 PM
Save date in filename Mike Excel Programming 6 February 24th 04 02:12 PM
Disabling Macros After A Save To A Different Filename R3df1sh[_2_] Excel Programming 2 November 14th 03 12:00 PM


All times are GMT +1. The time now is 09:13 AM.

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

About Us

"It's about Microsoft Excel"