Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default VBA Code--------!

Dear Friends,

Can Anybody provide with the vba code for merging all the worksheets of
all the open workbooks.

Ie; all the open workbooks' sheets should be moved to one neew
workbook.


Is this possible.


Regards
Thyagaraj

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA Code--------!

Hi Thyagaraj,

Can Anybody provide with the vba code for merging all the
worksheets of all the open workbooks.


Ie; all the open workbooks' sheets should be moved to one
neew workbook.


Try something like:

'=============
Public Sub MergeBooks()
Dim destWb As Workbook
Dim WB As Workbook
Dim SH As Worksheet
Dim i As Long
Dim sstr As String
Const sName As String = "My Summary"

sstr = Trim(sName) & " " & Format(Date, "yyyymmdd")

Set destWb = Workbooks.Add(xlWBATWorksheet)
Set SH = destWb.Worksheets(1)
SH.Name = "Summary"

Application.ScreenUpdating = False

With destWb
For Each WB In Application.Workbooks
If WB.Name < .Name _
And UCase(WB.Name) < "PERSONAL.XLS" Then
i = i + 1
WB.Worksheets.Copy after:=.Sheets(.Sheets.Count)
SH.Cells(i, "A").Value = WB.Name
SH.Cells(i, "B").Value = WB.Worksheets.Count
End If
Next WB
End With

destWb.SaveAs Filename:=sstr, _
FileFormat:=xlWorkbookNormal

Application.ScreenUpdating = True

End Sub
'<<=============


---
Regards,
Norman


"Thyagaraj" wrote in message
oups.com...
Dear Friends,

Can Anybody provide with the vba code for merging all the worksheets of
all the open workbooks.

Ie; all the open workbooks' sheets should be moved to one neew
workbook.


Is this possible.


Regards
Thyagaraj



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA Code--------!

Hi Thyagaraj,

In order to ensure better naming of the summary books worksheets and to
enable indentification of the source of these sheets, try the following
version:

'=============
Public Sub MergeBooks2()
Dim destWb As Workbook
Dim WB As Workbook
Dim SH As Worksheet
Dim i As Long, j As Long, k As Long, m As Long, n As Long
Dim sstr As String
Dim sStr2 As String
Const sName As String = "My Summary"

sstr = Trim(sName) & " " & Format(Date, "yyyymmdd")

Set destWb = Workbooks.Add(xlWBATWorksheet)
Set SH = destWb.Worksheets(1)
SH.Name = "Summary"

On Error GoTo XIT
Application.ScreenUpdating = False

With destWb
For Each WB In Application.Workbooks
If WB.Name < .Name _
And UCase(WB.Name) < "PERSONAL.XLS" Then
sStr2 = Replace(WB.Name, ".xls", "")
i = i + 1
j = destWb.Sheets.Count
WB.Worksheets.Copy after:=.Sheets(j)
k = destWb.Sheets.Count
For m = j + 1 To k
n = n + 1
destWb.Worksheets(m).Name = sStr2 & " Sh" & CStr(n)
SH.Cells(i, "A").Offset(0, n).Value = WB.Worksheets(n).Name
Next m
SH.Cells(i, "A").Value = WB.Name
j = 0: k = 0: m = 0: n = 0
End If

Next WB
End With

destWb.SaveAs Filename:=sstr, _
FileFormat:=xlWorkbookNormal
XIT:

Application.ScreenUpdating = True

End Sub
'<<=============

---
Regards,
Norman


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default VBA Code--------!


Norman Jones wrote:
Hi Thyagaraj,

In order to ensure better naming of the summary books worksheets and to
enable indentification of the source of these sheets, try the following
version:

'=============
Public Sub MergeBooks2()
Dim destWb As Workbook
Dim WB As Workbook
Dim SH As Worksheet
Dim i As Long, j As Long, k As Long, m As Long, n As Long
Dim sstr As String
Dim sStr2 As String
Const sName As String = "My Summary"

sstr = Trim(sName) & " " & Format(Date, "yyyymmdd")

Set destWb = Workbooks.Add(xlWBATWorksheet)
Set SH = destWb.Worksheets(1)
SH.Name = "Summary"

On Error GoTo XIT
Application.ScreenUpdating = False

With destWb
For Each WB In Application.Workbooks
If WB.Name < .Name _
And UCase(WB.Name) < "PERSONAL.XLS" Then
sStr2 = Replace(WB.Name, ".xls", "")
i = i + 1
j = destWb.Sheets.Count
WB.Worksheets.Copy after:=.Sheets(j)
k = destWb.Sheets.Count
For m = j + 1 To k
n = n + 1
destWb.Worksheets(m).Name = sStr2 & " Sh" & CStr(n)
SH.Cells(i, "A").Offset(0, n).Value = WB.Worksheets(n).Name
Next m
SH.Cells(i, "A").Value = WB.Name
j = 0: k = 0: m = 0: n = 0
End If

Next WB
End With

destWb.SaveAs Filename:=sstr, _
FileFormat:=xlWorkbookNormal
XIT:

Application.ScreenUpdating = True

End Sub
'<<=============

---
Regards,
Norman


Dear Norman,

This really great from your side, its working fine...........!


Thank u

regards
Thyagaraj

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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
run code on opening workbook and apply code to certain sheets Jane Excel Programming 7 August 8th 05 09:15 AM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM


All times are GMT +1. The time now is 09:36 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"