Disabling and enabling macros using code

Yeoman.jeremy

Board Regular
Joined
Apr 4, 2011
Messages
90
Hi there.

I need to include in one of my macros coding that disables certain macros, and enables others.

I have in my sheet checkboxes, that when ticked adjusts values on a different workbook, and when unchecked it reverts the values to how they were.
The problem with this is that my "clear all" macro unchecks these, which in turn reverts the values on the other workbook to how they were.

I tried to fix this by including in the "clear all" macro a bit of messy coding to add to the values on the other book to balance it out. so at the moment it does this.

(on check) adds one to a cell on the other workbook
(on "clear all")unchecks, therefore removing one from that cell on the other workbook
if checkbox_35 was checked, adds one to the cell again.

This DOES fix the problem, but it means that there is a whole load of screen flicking as it switches between workbooks.

Here is my code
Code:
Sub NewJobSheet_mcr()


Dim wbJobSheet As Workbook
Dim wbStats As Workbook
Dim strTestFileName As String
Dim srtPath As String
 
   Set wbJobSheet = ThisWorkbook ' create reference to the workbook the code is in
 
   strPath = "C:\Users\owner\Desktop\Presentation Job Sheet\"
   
   strTestFileName = "Quoting Statistics"
 
   ' open and create a reference to the 'Test Over WBk' workbook
    On Error Resume Next

If Sheets("Job Sheet").CheckBox35 = True Then
Set wbStats = Workbooks.Open(strPath & strTestFileName)
With wbStats.Sheets("Sheet1")
.range("D5").Value = .range("D5") + 1
End With
End If
If wbJobSheet.Sheets("Job Sheet").CheckBox38 = True Then
   With wbStats.Sheets("Sheet1")
.range("f5").Value = .range("f5") + 1
End With
End If
With wbStats.Sheets("Sheet1")
.range("E5").Value = .range("E5") + 1
wbStats.Close (True)
End With
Call ClearForm_mcr
  Call Uncheck


Call AlterDuplicate_mcr
 ThisFile = range("J6").Value
    ChDir "C:\Users\owner\Desktop\Development\Quotes to sort"
    ActiveWorkbook.SaveAs FileName:=ThisFile
 Call ReturnDuplicate_mcr
   Call ClearForm_mcr
  Call Uncheck
[g2] = [g2] + 1
    
    
    


End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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