Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copying data into a number of other workbooks

Hi,

I'm trying to write a macro that copies a data range from this
workbook into a number of other workbooks specified by the user. The
macro so far is as set out below but it keeps failing at the Paste
stage and I think the copy command is deactivated by that point. I
don't know how to correct the code. Any help is appreciated.

Thanks

Sub DataUpdate()

Dim fn As Variant, f As Integer

ActiveSheet.Unprotect Password:="Password"

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False

Set SumSht = ThisWorkbook.Sheets("Standard Risk Descriptions")

fn = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select ALL the current Risk Registers that you wish to
update", , True)
If TypeName(fn) = "Boolean" _
Then
ActiveSheet.Protect Password:="Password",
DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingColumns:=True
Range("I2").Select

Exit Sub
Else
End If

Application.ScreenUpdating = True
Application.ScreenUpdating = False



Sheets("Standard Risk Descriptions").Select
Range("B4:C29").Select
Selection.Copy

For f = 1 To UBound(fn)
Workbooks.Open fn(f)
On Error GoTo Errhandler1
Sheets("Standard Risk Descriptions").Select
ActiveSheet.Unprotect Password:="Password"
Range("B4:C29").Select
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Protect Password:="Password",
DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingRows:=True, AllowFiltering:= _
True

Call CloseAllInactive
Next f

Application.CutCopyMode = False

Range("i4").Select

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True

ActiveSheet.Protect Password:="Password", DrawingObjects:=True,
Contents:=True, Scenarios:=True _
, AllowFormattingRows:=True, AllowFiltering:= _
True

MsgBox "The update data process" & vbNewLine & _
"has finished."

Exit Sub

Errhandler1:

' If an error occurs, display a message and end the macro.
MsgBox "You have selected an incorrect spreadsheet" & vbNewLine
& _
"(i.e. not a standard risk register spreadsheet)." & vbNewLine
& vbNewLine & _
"The macro will now end and you need to start again."

ThisWorkbook.Activate

Call CloseAllInactiveUnsaved

Exit Sub


End Sub

Public Sub CloseAllInactive()

Dim Wb As Workbook
Dim AWb As String
AWb = ActiveWorkbook.Name

For Each Wb In Workbooks
If Wb.Name < AWb Then
Wb.Save
Wb.Close savechanges:=True
End If
Next Wb

End Sub

Public Sub CloseAllInactiveUnsaved()

Dim Wb As Workbook
Dim AWb As String
AWb = ActiveWorkbook.Name

For Each Wb In Workbooks
If Wb.Name < AWb Then
Wb.Close savechanges:=False
End If
Next Wb

End Sub


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
Copying data between workbooks Karen53 Excel Programming 4 February 23rd 08 01:29 AM
copying same data to several Workbooks Miranda Excel Programming 1 March 2nd 07 06:27 PM
Copying data between Workbooks STEVEB Excel Programming 0 November 16th 05 07:06 PM
Copying data between workbooks? One Desperate Employee! Excel Discussion (Misc queries) 5 September 24th 05 09:41 AM
Copying Data from closed workbooks Kevin G Excel Programming 4 July 31st 03 03:46 PM


All times are GMT +1. The time now is 12:10 AM.

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"