LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Can you copy a worksheet from a workbook wothout opening it?

Thanks Jim!

I don't think there's much difference in the speed but the Status bar text
and hiding the taskbar buttons adds a nice professional touch.

cheers,

Damien

"Jim Cone" wrote in message
...

I modified the code somewhat with the intent of speeding it up,
but I can't test it. Even if the speed is not much different,
hiding the workbook buttons in the Taskbar and displaying a
message in the StatusBar will make it seem faster.

1. All variables were declared and two new ones added.
2. I assumed that the code was in workbook
"Operating Report - Southern Summary.xls" and used "ThisWorkbook"
instead, in several places.
3. Like your line labels.
4. I assume the wsExists function is efficiently constructed.

'--
Sub ImportSummaries()
On Error GoTo Hell
Dim wbName As String
Dim PathName As String
Dim YearPeriod As String
Dim WSName As String
Dim wk As String
Dim branch As Excel.Range
Dim NewBook As Excel.Workbook
Dim blnShow As Boolean

Application.ScreenUpdating = False
blnShow = Application.ShowWindowsInTaskbar
Application.ShowWindowsInTaskbar = False
YearPeriod = ThisWorkbook.Worksheets("Summary").Range("YearPeri od")
PathName = "C:\OpsReport\" & YearPeriod & "\"
wk = Worksheets("Summary").Range("Weekno")

For Each branch In Worksheets("Tables").Range("BusAreaList").Cells
wbName = branch.Text & " " & YearPeriod & " wk " & wk & ".xls"
WSName = branch.Text

If wsExists(WSName) Then
Application.DisplayAlerts = False
Worksheets(WSName).Delete
Application.DisplayAlerts = True
End If

If Not CBool(Len(Dir(CStr(PathName & wbName)))) Then
MsgBox "There's no data to import for " & WSName, , "Operating Report"
Else
Application.StatusBar = "Processing " & wbName
Set NewBook = Workbooks.Open(PathName & wbName)
NewBook.Worksheets(WSName).Copy _
After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksh eets.Count)
NewBook.Close savechanges:=False
End If
Next ' branch

Gout:
Set branch = Nothing
Set NewBook = Nothing
Application.StatusBar = False
Application.ShowWindowsInTaskbar = blnShow
Application.ScreenUpdating = True
Exit Sub
Hell:
MsgBox Err.Description, , "Operating Report"
Resume Gout
End Sub
'--

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Damien McBain"
wrote in message
Why? Are you trying to make the code run faster?

Yep :-)






 
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
create copy of sheet tab (excel 2007) when opening workbook jatman Excel Worksheet Functions 1 February 29th 08 12:26 PM
Prevent worksheet from opening in a workbook laurenm Excel Worksheet Functions 5 January 18th 07 05:42 AM
Is there away to keep Excel from opening a copy of an already opened workbook and the pages not be at 100% but Marc New Users to Excel 1 March 13th 06 01:51 PM
Copy to different workbook without opening it JNW Excel Programming 4 December 2nd 05 09:03 PM
Copy a worksheet without 'opening' workbook SteveS[_3_] Excel Programming 2 October 11th 04 06:02 PM


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