Copy or replace sheet1 from a closed workbook
On further thought, cured the problem by turning firing the macros in the
first WB only if the second WB is not open. Now I can stick with my original
copy from first WB code.
--
Steve
"Steve" <No Spam wrote in message ...
The book needs to remain closed to prevent a macro from firing.
In a round-about you response seems to be saying I can't copy from a
closed book. That being the case, I'll write some code to link the data
then copy/paste special.
"Norman Jones" wrote in message
...
Hi Steve,
Thank you, but only works if WB is open. I need to grab data from a
closed WB
Try:
'=============
Private Sub Workbook_Open()
Dim WB As Workbook
Dim SH As Worksheet
Dim blClosed As Boolean
On Error Resume Next
Set WB = Workbooks("FirstBook.xls") '<<==== CHANGE
On Error GoTo 0
If WB Is Nothing Then
blClosed = True
Application.ScreenUpdating = False
Set WB = Workbooks.Open("FirstBook.xls")
End If
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE
On Error GoTo 0
With Me.Sheets("Sheet1")
.Cells.Clear
SH.Cells.Copy Destination:=.Range("A1")
End With
If blClosed Then WB.Close (False)
Application.ScreenUpdating = True
End Sub
'<<=============
---
Regards,
Norman
|