Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trap insert row or column in Excel in VBA

Hello,

Could you have any idea how to do it ?. I was looked anywhere and not
founded any information about that.
I know, i may use the workbook onchange or calculate event, but i must
necessarily get it just at this event moment.
Please, help me !!!

Thx in advance
Grzegorz


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Trap insert row or column in Excel in VBA

I believe you are out of luck, Grzegorz. No such event. You must play around
with combinations of selectionchange, change and calculate events to trap
what you look for.

Or just protect the worksheet. No columns can be added or deleted from then
on without your very own column_insert macro.

HTH. Best wishes Harald


"Grzesiek" skrev i melding
...
Hello,

Could you have any idea how to do it ?. I was looked anywhere and not
founded any information about that.
I know, i may use the workbook onchange or calculate event, but i must
necessarily get it just at this event moment.
Please, help me !!!

Thx in advance
Grzegorz




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Trap insert row or column in Excel in VBA

Hi Grzesiek,

I just asked a similar question on this forum, and got a good answer. Try
the following code:


Public Sub MyInsertRow()
Dim Mycontrol As CommandBarControl
Set Mycontrol = Application.CommandBars("Worksheet Menu Bar").FindControl
_(ID:=296, Recursive:=True)
Mycontrol.OnAction = ThisWorkbook.Name & "!mymacro"
End Sub

Public Sub MyMacro()
MsgBox "Hi"
End Sub

When "Insert Row" is then selected, MyMacro will run instead. If you really
want to insert a row, your macro will need code to make this happen. To
reset the menu item to get the standard menu "Insert Row" to work, use the
code:

Public Sub MyResetInsertRow()
Dim Mycontrol As CommandBarControl
Set Mycontrol = Application.CommandBars("Worksheet Menu Bar").FindControl
_(ID:=296, Recursive:=True)
Mycontrol.OnAction = ""
End Sub

For "Insert Column" use ID:=297. Good luck!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Trap insert row or column in Excel in VBA

Hi Filibuster

It's cool !!! , thank you it's work, but i found one way in this
solution , where my macro isn't work - i don't know why (i think, i
must use other id, but which ? ) , I was tested with :
Set Mycontrol = Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=296, Recursive:=True)
Set Mycontrol2 =
Application.CommandBars("Cell").FindControl(ID:=31 81, Recursive:=True)
Set Mycontrol3 =
Application.CommandBars("Cell").FindControl(ID:=29 2, Recursive:=True)
and in my opinion Mycontrol2 must worked when I click right mouse
button (insert) on the number row in Excel, but this solution not work
for this - its work when i execute this on any cells in excel.
Do you know which id i must use for this ?

Thank you again

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Trap insert row or column in Excel in VBA

Grzes,

Your ID values look correct for the Insert and Delete functions of the right
click menu. I tried your code, and it works for me. Did you remember to
assign a macro to your newly defined controls:
MyControl2.OnAction = ThisWorkbook.Name & "!mymacro2"
MyControl3.OnAction = ThisWorkbook.Name & "!mymacro3"



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Trap insert row or column in Excel in VBA

Hello,

It's working ok. now, thank you very much again.


Best regards

Grzegorz

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to trap an 'Insert Row' via VBA ? TRB Excel Programming 3 April 22nd 06 09:57 PM
How to trap delete row event and hide column event? Alan Excel Programming 3 April 26th 05 04:25 PM
Excel Version Trap amescha Excel Programming 12 June 29th 04 06:16 PM
Trap Right CLick Insert Von Shean Excel Programming 1 January 22nd 04 04:42 AM
Trap Excel events from VB pat Excel Programming 0 August 18th 03 11:01 PM


All times are GMT +1. The time now is 03:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"