Workbook Won't Close

ColoKevMan

New Member
Joined
Jun 26, 2015
Messages
11
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This code works ... except the Master workbook does not close. Can anyone tell me why?
You could try removing ?web=1 from the end of your Master workbook path.
I stumbled onto this thread that recommends not using that in the path for Workbook vba variables.
Redirecting
Hope this helps...
 
Upvote 0
Solution
I would say in general to remove any URL parameters, that is, a "?" and anything after it.
 
Upvote 0
So far so good after removing URL parameters. URL Parameters were included because the workbook wouldn't open initially without them, but is doing so now. Don't understand

Thanks for the help!!
 
Upvote 0
The parameters give information to the web server that is specific to that URL. I don't know what SharePoint does with that, but it probably sends back a web page response instead of the file.
 
Upvote 0

Forum statistics

Threads
1,225,291
Messages
6,184,096
Members
453,213
Latest member
redchief

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top