dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,392
- Office Version
- 365
- 2016
- Platform
- Windows
I have some code that is meant to save and close the workbook identified in the select statement (Wes_reference or Riv_reference) but it is not closing it. What have I left out?
Code:
Sub AddReference()
Dim wb1 As Workbook, wb2 As Workbook
Dim sh1 As Worksheet, sh2 As Worksheet, site As String
Dim f As Range, client As Variant, Ref As String, ref2 As String
Set wb1 = ThisWorkbook
Set sh1 = wb1.Worksheets("quote_sheet")
'set site = site name selected on Start_here sheet
site = ThisWorkbook.Worksheets("Start_here").Range("H9")
'open the reference number sheet for the site that has been selected on the sheet Shart_here
Select Case site
Case "Wes"
If Not isFileOpen("Wes_reference.xlsm") Then
Workbooks.Open ThisWorkbook.Path & "\" & "Wes_reference.xlsm"
End If
Set wb2 = Workbooks("Wes_reference")
Set sh2 = wb2.Sheets("Wes_reference")
Case "Riv"
If Not isFileOpen("Riv_reference.xlsm") Then
Workbooks.Open ThisWorkbook.Path & "\" & "Riv_reference.xlsm"
End If
Set wb2 = Workbooks("Riv_reference")
Set sh2 = wb2.Sheets("Riv_reference")
End Select
Ref = sh2.Cells(Rows.Count, 1).End(xlUp).Value
ref2 = Ref + 1
sh2.Cells(1, 1).End(xlDown).Offset(1, 0).Value = ref2
sh1.Range("H5").Value = ref2
With wb2
.Save
.Close
End With
End Sub