K
KR
I have about 300 workbooks (different users, all in the same network
directory) and now I need to pull data out of the same worksheet for each
user- into one workbook so I can run some statistics on all the data
combined.
For testing purposes, my code is below, but I'm having trouble getting it to
paste (then close) properly.
Info: Win2000, Excel 2003
Each workbook's data sheet is protected, so I need to unprotect it (to copy)
then reprotect it before exiting
Each workbook has an onopen even that links it to a third workbook to upload
the most current source data for some worksheets in the workbook
Each workbook's before_close event includes code that saves the workbook as
part of the close (no warnings or pop-ups)
Once I get this working for one workbook, it should be easy to modify the
code to loop through each workbook in the target network directory.
Thanks for helping,
Keith
Sub GrabMyData()
Dim Owkbk As Workbook
Set Owkbk = ActiveWorkbook
Dim wkbk As Excel.Workbook
On Error Resume Next
Set wkbk = Workbooks.Open(\\mynetworkpath\ & "filename" & ".xls", 0,
True)
On Error GoTo 0
wkbk.Activate
'wkbk.Sheet1.Unprotect
wkbk.Sheets("Data Entry").Unprotect
wkbk.Sheets("Data Entry").Activate
LastRow = wkbk.Sheets("Data Entry").Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row
wkbk.ActiveSheet.Range("A13:Z" & Trim(Str(LastRow))).Select
Selection.Copy
Application.CutCopyMode = False
Owkbk.Activate
Owkbk.Sheets("Sheet1").Range("A1").Select
Owkbk.ActiveSheet.Paste ' ******* it doesn't like this line *******
wkbk.Activate
wkbk.Sheet1.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
wkbk.Sheet1.EnableSelection = xlNoSelection
wkbk.Close (False)
End Sub
directory) and now I need to pull data out of the same worksheet for each
user- into one workbook so I can run some statistics on all the data
combined.
For testing purposes, my code is below, but I'm having trouble getting it to
paste (then close) properly.
Info: Win2000, Excel 2003
Each workbook's data sheet is protected, so I need to unprotect it (to copy)
then reprotect it before exiting
Each workbook has an onopen even that links it to a third workbook to upload
the most current source data for some worksheets in the workbook
Each workbook's before_close event includes code that saves the workbook as
part of the close (no warnings or pop-ups)
Once I get this working for one workbook, it should be easy to modify the
code to loop through each workbook in the target network directory.
Thanks for helping,
Keith
Sub GrabMyData()
Dim Owkbk As Workbook
Set Owkbk = ActiveWorkbook
Dim wkbk As Excel.Workbook
On Error Resume Next
Set wkbk = Workbooks.Open(\\mynetworkpath\ & "filename" & ".xls", 0,
True)
On Error GoTo 0
wkbk.Activate
'wkbk.Sheet1.Unprotect
wkbk.Sheets("Data Entry").Unprotect
wkbk.Sheets("Data Entry").Activate
LastRow = wkbk.Sheets("Data Entry").Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row
wkbk.ActiveSheet.Range("A13:Z" & Trim(Str(LastRow))).Select
Selection.Copy
Application.CutCopyMode = False
Owkbk.Activate
Owkbk.Sheets("Sheet1").Range("A1").Select
Owkbk.ActiveSheet.Paste ' ******* it doesn't like this line *******
wkbk.Activate
wkbk.Sheet1.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
wkbk.Sheet1.EnableSelection = xlNoSelection
wkbk.Close (False)
End Sub