adding code to existing code

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings, I have learned a lot from all of you gurus out there, but I am still such a noob. I am using the following code to launch a custom tool bar:

Code:
Private Sub WorkBook_Activate()
    On Error Resume Next
 
        With Application.CommandBars("Daily Checklist")
            .Enabled = True
                .Visible = True
                End With
        On Error GoTo 0
 
End Sub

Now I would like to add the following snippet to disable the ability in the WB to drag and drop. But I can't figure out how to add that in without getting errors.

Code:
Application.CellDragAndDrop = False

Could someone give me a little help on adding the drag and drop code into the workbook_deactivate sub - thanks, RB

P.S - if anyone knows of a book that details how to structure codes in this kind of detail I would buy it in a minute!;)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Thanks for the response, that certainly is another way of doing it, but I still dont know how to enter in that snippet of code to existing code, that is where my limited knowledge gets me stuck....
 
Upvote 0
rickblunt,

I tested your WorkBook_Activate code below, without the code for the CommandBars section, and after I saved the test workbook, and opened it again, I was NOT able to drag and drop.



Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Rich (BB code):
Private Sub WorkBook_Activate()
On Error Resume Next
With Application.CommandBars("Daily Checklist")
  .Enabled = True
  .Visible = True
End With
On Error GoTo 0

On Error Resume Next
Application.CellDragAndDrop = False
On Error GoTo 0

End Sub
 
Upvote 0
Thanks Hiker, your code is one of the ways I tried it, so it looks like I was on the right track, but I get errors. I will dig a lot deeper and see if I can track it down. At least you have confirmed that my syntax is correct, that is very helpful. I appreciate it - RB
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

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