Darren Smith
Well-known Member
- Joined
- Nov 23, 2020
- Messages
- 631
- Office Version
- 2019
- Platform
- Windows
Trying to use a listbox click to clear the tabs from a active workbook except for the first 4 tabs. Then open a new workbook from listbox item and copy all tabs then paste into the active workbook. Code below clears all tabs except the first 4 then opens the correct workbook but does not copy and paste??
Private Sub ListBox3_Click()
For i = 0 To Me.ListBox3.ListCount - 1
If Me.ListBox3.Selected(i) Then
Workbooks.Open "\\TGS-SRV01\Share\ShopFloor\PRODUCTION\DLS Cardworker\Jobcard Templates\" & Me.ListBox3.List(i)
Exit For
End If
Next i
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Dim sht As Worksheet
Set wkbDest = Workbooks("Automated Cardworker.xlsm")
If Me.ListBox3.ListIndex > -1 Then
Set wkbSource = Workbooks(Me.ListBox3.Value)
Application.DisplayAlerts = False
Do While wkbDest.Sheets.Count > 4
wkbDest.Sheets(wkbDest.Sheets.Count).Delete
Loop
Set shttocopy = wkbSource.Sheets
shttocopy.Copy
wkbDest.Sheets(wkbSource).Select
wkbDest.Paste
Application.DisplayAlerts = True
End If
End Sub
Last edited: