StillUnderstanding
Board Regular
- Joined
- Jan 30, 2021
- Messages
- 80
- Office Version
- 365
- Platform
- Windows
- MacOS
Hello,
I wonder if anyone can help me with a problem I am stuck on. I am using code that allows me to duplicate my workbook and then save it to another location. What I am trying to do is delete some of the modules from the duplicated workbook before saving.
I am using the below code and everything works apart from the module deleting part. Can anyone please help me with this please?
I wonder if anyone can help me with a problem I am stuck on. I am using code that allows me to duplicate my workbook and then save it to another location. What I am trying to do is delete some of the modules from the duplicated workbook before saving.
I am using the below code and everything works apart from the module deleting part. Can anyone please help me with this please?
VBA Code:
'Create duplicate in temp folder.
ThisWorkbook.SaveCopyAs strTempFolderPath & "2022a.xlsb"
Application.Wait (Now + TimeValue("0:00:05"))
'2) ----------> Open the duplicate file
Set wbDuplicate = Workbooks.Open(strTempFolderPath & "2022a.xlsb")
Dim vbCom As Object
'Disabling the alert message
Application.DisplayAlerts = False
'Ignore errors
On Error Resume Next
'Delete the component
wb.VBProject.VBComponents.Remove wb.VBProject.VBComponents("test", "Module111", "Module3")
On Error GoTo 0
'Enabling the alert message
Application.DisplayAlerts = True
On Error GoTo 0
'Next
'3) ----------> Close all tabs except the following:
'- Import Core Data
'- SendMail
'- Test CP Weekly
Worksheets("Lookup").Unprotect
For Each shSheet In wbDuplicate.Sheets
If shSheet.Name <> "TAB 1" And shSheet.Name <> "TAB2" And shSheet.Name <> "Tab3" Then
shSheet.Visible = xlVeryHidden
Sheets("Tab3").Visible = False