ColoKevMan
New Member
- Joined
- Jun 26, 2015
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
This code works ... except the Master workbook does not close. Can anyone tell me why?
VBA Code:
Sub CopyBuyersIRth()
' Copy Buyers IR tab from Master
Dim Currentwb As Workbook
Dim Master As Workbook
Dim WS_Master As Worksheet, WS_BDA As Worksheet, WS_New As Worksheet, WS_Master1 As Worksheet, WS_New1 As Worksheet
Dim CopyRange As Range
Application.ScreenUpdating = False
Set Currentwb = ThisWorkbook
'Check if Tina H sheet exists
On Error Resume Next
Set WS_BDA = Currentwb.Sheets("Tina H")
On Error GoTo 0
'
If WS_BDA Is Nothing Then
MsgBox "Error-problem finding worksheet 'Tina H'", vbCritical
Exit Sub
End If
'Open the Master workbook
On Error Resume Next
Set Master = Workbooks.Open("https://fotf.sharepoint.com/sites/BSG/Shared%20Documents/General/BDA-Open POs/OpenPOBDA-all.xlsm?web=1")
On Error GoTo 0
If Master Is Nothing Then
MsgBox "Error-problem opening OpenPOBDA-all workbook", vbCritical
Exit Sub
End If
'Copy the "Buyer IRs" sheet
On Error Resume Next
Set WS_Master = Master.Worksheets("Buyer IRs")
On Error GoTo 0
If Not WS_Master Is Nothing Then
WS_Master.Copy After:=WS_BDA
Set WS_New = ActiveSheet
With WS_New
Set CopyRange = .Range("K2:K" & .Range("A" & .Rows.Count).End(xlUp).Row)
CopyRange.Value = CopyRange.Value
End With
Else
MsgBox "Error-problem finding worksheet 'Buyer IRs'", vbCritical
End If
'Copy the "Purchase Line Items - All OPEN" sheet
On Error Resume Next
Set WS_Master1 = Master.Worksheets("Purchase Line Items - All OPEN")
On Error GoTo 0
If Not WS_Master1 Is Nothing Then
WS_Master1.Copy After:=WS_BDA
Set WS_New1 = ActiveSheet
With WS_New1
Set CopyRange = .Range("R2:T" & .Range("A" & .Rows.Count).End(xlUp).Row)
CopyRange.Value = CopyRange.Value
End With
Else
MsgBox "Error-problem finding worksheet 'Purchase Line Items - All OPEN'", vbCritical
End If
'
'Close the Master workbook without saving changes
Master.Close Savechanges:=False
'Activate "Tina H" sheet and create formula
WS_BDA.Activate
WS_BDA.Range("H2").Activate
ActiveCell.Formula = "=Purchase_Line_Items___All_OPEN[@Updated]"
WS_BDA.Range("G9").Select
Application.ScreenUpdating = True
End Sub