LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Create New Worksheets in VB

bbrendan

The code looks okay to me. What do you mean it crashes out? Do you get an
error, and on which line?

I wonder if Summary_AllAreas.xls is the second workbook found and since it's
already open causes problems with the FileSearch. Just a guess though.
Even if that's not the problem, it seems like you'd need some code in there
to skip your AllAreas workbook anyway.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"bbrendan " wrote in message
...
Hi,

I know this is an excel forum, but this is what I would like to do

I have a VB app, which creates multiple workbooks in one folder.
I would like to take each workbook (they ony have one sheet in each)
and combine them into one workbook.

So far I have found this code from this site. It seems to work fine if
I use it in excel, but I would like to use it from VB.

i have the references setup, but when it loops through the first time
it then crashes out.

Any ideas? please


----------------------------------------------------------------
Dim oExcel As Excel.Application
Dim basebook As Workbook
Dim mybook As Workbook
Dim i As Long

Set oExcel = New Excel.Application

Application.ScreenUpdating = False
With Application.FileSearch
NewSearch
LookIn = "c:\xlsdata" ' This is the folder containing the
workbooks
SearchSubFolders = False
FileType = msoFileTypeExcelWorkbooks
'msoFileTypeExcelWorkbooks

If .Execute() 0 Then

Set basebook =
oExcel.Workbooks.Open("\c:\xlsdata\Summary_AllArea s.xls")
'ThisWorkbook to hold all sheets
For i = 1 To .FoundFiles.Count
Set mybook = Workbooks.Open(.FoundFiles(i))
mybook.Worksheets(1).Copy
after:=basebook.Sheets(basebook.Sheets.Count)
ActiveSheet.Name = mybook.Name
mybook.Close
basebook.Close
Next i
End If

End With
Application.ScreenUpdating = True
---------------------------------------------------------------------


---
Message posted from http://www.ExcelForum.com/



 
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
Automatically create worksheets Bryan Excel Discussion (Misc queries) 1 January 18th 08 06:46 AM
How use info in Excel shared worksheets to create new worksheets dkc Excel Worksheet Functions 0 June 28th 07 08:36 PM
Create workbooks from worksheets Ian in Ankara Excel Discussion (Misc queries) 3 February 28th 06 03:33 PM
I want to create and name 365 worksheets... Dr. Darrell Excel Worksheet Functions 1 December 8th 05 01:00 PM
Excel VBA - Create worksheets ozcank Excel Programming 11 January 28th 04 09:53 AM


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

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"