0

I wrote VBA code that updates changes made in Excel to a database (SQL server).
How can I distribute this code to other users?
I stored the changed values in an array using the Worksheet_Change subroutine.

Sub Worksheet_Change(ByVal Target As Range)
   'add value to array
End sub

I also have code to update the database:

Sub update_database()
  'update database
End sub

I stored both subroutines in the sheet1 code.

How can I distribute this macro without the user copying and pasting my code?
I know that I can put my macro in quick link. But I don't know how to deal with the Worksheet_Change procedure which I think is bound to the sheet.

Community
  • 1
  • 1
kinkajou
  • 3,664
  • 25
  • 75
  • 128
  • 2
    you can use vba event in addins - see [this MSDN article](http://msdn.microsoft.com/en-us/library/cc668205.aspx) for more information and this [SO thread](http://stackoverflow.com/questions/7596623/what-is-the-best-way-to-share-distribute-excel-macro/7597071#7597071) to distribute vba – JMax Oct 06 '11 at 07:38

1 Answers1

3

Put your code in an Addin and distribute that.

Note: to make the addin respond to all Worksheet_Change events, see How can an Excel Add-In respond to events in any worksheet?

Community
  • 1
  • 1
chris neilsen
  • 52,446
  • 10
  • 84
  • 123