Cant enter break mode error received when copying sheet

Joseph Schneider

New Member
Joined
Dec 9, 2021
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello :)

Help would be greatly appreciated as I have spent a while debugging going through my reference libraries and searching online for a solution none of which matched my issues or were solved.

Error Line: Sht_Vehicle.Copy After:=Sheets(Worksheets.Count)
"Sht_Vehicle" is the code name for a sheet
When I attempt to run this line I get the message "cant enter break mode" there is only continue, end and help as options.
When I put the line of code in a module by itself it works just fine.
There is a lot going on in this workbook but I attached the section where the error is.
 

Attachments

  • Error Source.PNG
    Error Source.PNG
    122 KB · Views: 24

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hello,

Being that no one had a solution for my issue I went and created the sheet the long way by creating the sheet from scratch instead of copying it. Sad to think all this could have been 10 lines intead of 50 but at least the program works. I will keep this page bookmarked if anyone has a better idea. Thanks

If you are interested in seeing what the code does checkout the following video I recorded: << unavailable video removed >>

'*************************************************************************************************************************************************************************'
'Proceeding to Create new sheet for user.
'Sht_TemplateVehicle.Copy After:=Sheets(Sheets.count)

'Code to recreate the Template vehicle sheet since I cant copy it
Str_ShtNewVehicleName = TxtBx_AddAccountColor & " " & TxtBx_AddAccountYear & " " & TxtBx_AddAccountMake & " " & TxtBx_AddAccountModel
Str_ShtNewVehicleCodeName = TxtBx_AddAccountColor & TxtBx_AddAccountYear & TxtBx_AddAccountMake & TxtBx_AddAccountModel

Arr_NewVehicleData = Array("Oil Change", "", Format(Date, "mm/dd/yyyy"), Replace(TxtBx_AddAccountMileage, ",", ""), Format(DateAdd("m", 6, Date), "mm/dd/yyyy"), _
Replace(TxtBx_AddAccountMileage, ",", "") + 5000, , "", 5000, 6)

Arr_NewVehicleHeaders = Array("Service Item", "Item Life Remaining (%)", "Service Date", "Service Mileage (Miles)", "Service Due (Date)", "Service Due (Miles)", _
"Service Notes", "Interval (Miles)", "Interval (Months)")

'1) Create and Sht Name and Code Name (DONE)
Sheets.Add(After:=Sheets(Sheets.Count)).Name = Str_ShtNewVehicleName
Set Sht_NewVehicleSht = Sheets(Sheets.Count)
ThisWorkbook.VBProject.VBComponents(Sht_NewVehicleSht.CodeName).Name = Str_ShtNewVehicleCodeName

'2) Black out sheet Cells (DONE)
Sht_NewVehicleSht.Cells.Interior.Color = Lng_BlackColor

'3) Create Table and Format (DONE)
Set LstObj_NewVehicle = Sht_NewVehicleSht.ListObjects.Add(SourceType:=xlSrcRange, Source:=Sht_NewVehicleSht.Range(Cells(2, 1), Cells(2, 9)))
With LstObj_NewVehicle
.Range.Interior.Color = xlNone
.Name = Replace(Sht_NewVehicleSht.Name, " ", "")
.TableStyle = "Vehicle_PM"
.HeaderRowRange = Arr_NewVehicleHeaders
.ListRows.Add: .ListRows(1).Range = Arr_NewVehicleData
.HeaderRowRange.Font.Size = 12
.ListColumns(4).DataBodyRange.NumberFormat = "#,##0"
.ListColumns(6).DataBodyRange.NumberFormat = "#,##0"
.ListColumns(9).DataBodyRange.NumberFormat = "#,##0"
.Range.HorizontalAlignment = xlCenter
.ListColumns(1).DataBodyRange.HorizontalAlignment = xlLeft
.ListColumns(7).DataBodyRange.HorizontalAlignment = xlLeft
.Range.BorderAround Weight:=xlMedium, Color:=Lng_WhiteColor
End With
Sht_NewVehicleSht.Columns.AutoFit
Sht_NewVehicleSht.Rows(1).RowHeight = 40

'4) Copy Code from Template Vehicle to new Sht (DONE)
'*** IF YOU ARE WONDERING WHY ALL THE COMMENTS, I SAVE THIS TEMPLATE AS A NOTEPAD FILE AND EDIT IT FOR MY WORKBOOKS WHEN I NEED IT. ***

'This code will break if you have not enabled Extensibility 5.3 | Go to tools > References > Microsoft Visual Basic for Applications Extensibility 5.3
Dim Code_SourceModule As VBIDE.CodeModule, Code_DestinationModule As VBIDE.CodeModule
Dim Int_ModCodeLines As Integer

Set Code_SourceModule = ActiveWorkbook.VBProject.VBComponents(Sht_TemplateVehicle.CodeName).CodeModule 'This is an existing sht so I added ".codename"
Set Code_DestinationModule = ActiveWorkbook.VBProject.VBComponents(Str_ShtNewVehicleCodeName).CodeModule 'This is a variable storing the codename as text so no ".codename" needed
Int_ModCodeLines = Code_SourceModule.CountOfLines

'The line below removes code in destination Sht if there is any. Cant paste of code exists in module.
If Code_DestinationModule.CountOfLines > 1 Then Code_DestinationModule.DeleteLines 1, Code_DestinationModule.CountOfLines

On Error Resume Next '*This is needed as the code breaks on the next line but works if you run it all the way through
Code_DestinationModule.AddFromString Code_SourceModule.Lines(1, Int_ModCodeLines)

'*************************************************************************************************************************************************************************'
For Each Sht In ThisWorkbook.Worksheets
If Not Sht Is Sht_Login Then Sht.Visible = xlVeryHidden
Next Sht
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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