Workbook with no code now ... will need macro functionality later

B

Barb Reinhardt

I'm working with a group that has vanilla flavored workbook (no code) that
they want to deploy. At some time in the future, they want to be able to
add code to that workbook.

The options I can come up with are:

1) Use functionality such the stuff on Chips site about Programming in the
VBA editor to add the code to the now vanilla workbook. The problem I can
forsee is that the macros would still need to be enabled each time the
workbook is opened. I don't want to recommend that people set their
security to LOW. We're looking at digital signatures as well, but as I
understand it the code would need to be signed after it's in the workbook and
I"m guessing that can't be done programmatically.

2) Put the code in an Add-In that's distributed later. I've only done
this once and had to select a referece to the Add-in in the VBE. I'm
thinking that we can decide on the name for the Add-in now and set the
reference to it. When the add-in is deployed, the reference will already be
set and it'll be ready to go.

Comments/Suggestions. Am I completely on the wrong track?

Thanks,
Barb Reinhardt
 
B

Barb Reinhardt

I'm also considering doing something like a Compare add-in I picked up
somewhere. When the add-in is enabled, something is added to the Tools menu
for execution. I'm thinking that when we move to Office 2007, this will be
in an XLAM and I'll have to convert. OK, I know I've asked too many
questions for one thread so will stop for now.

Barb Reinhardt
 
P

Peter T

I would go with your idea putting all your code in an addin. Not why sure
you would need any references at all (I assume you are talking about Tools,
Ref's). Only reason to do that is to be able to call code in the referenced
workbook as if it is in the same workbook; presumably that scenario would
not exist if there is no code in the deployed workbooks.

You can trap events of any or all open workbooks at sheet or workbook level
from within your addin (in addition to application level events), if that's
an objective.

Regards,
Peter T
 
B

Barb Reinhardt

I'm familiar with workbook events in a specific workbook. Can you direct me
to how I'd do that with an Add-In?

Thanks,
Barb Reinhardt
 
P

Peter T

Following into a normal module and two class modules. Run "Trapem". Switch
between workbooks and select cells. the application level class will trap
all events, the workbook level class just thos in Book1.xls

'' normal module

Dim mAppEvnts As clsApp

Dim mWbEvnts As clsWB

Sub Trapem()

Set mAppEvnts = New clsApp
Set mAppEvnts.xlApp = Application

Set mWbEvnts = New clsWB
Set mWbEvnts.pWb = Workbooks("Book1.xls") ' some other book

End Sub

'' end normal module


' Class module named clsApp

' Application level events
Public WithEvents xlApp As Excel.Application

Private Sub xlApp_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)
MsgBox Target.Address(external:=True), , "xlApp_SheetSelectionChange"
End Sub

' in the upper left combo select "xlApp"
' in the upper right dropdown select events


Private Sub xlApp_WorkbookActivate(ByVal Wb As Workbook)

MsgBox Wb.Name, , "xlApp_WorkbookActivate"

' maybe go on to create a withevents class to trap Wb's events
' at Workbook level
End Sub

'' end clsApp


' Class module named clsWb

' Workbook level events
Public WithEvents pWb As Excel.Workbook

' in the upper left combo select "pWb"
' in the upper right dropdown select events

Private Sub pWb_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)
MsgBox Target(1).Address(external:=True), , "pWb_SheetSelectionChange"
End Sub

'' end clsWb


You would only have one instance of application level events but you could
have multiple withevents classes to trap workbook events. Rather than the
single object ref to the class "mWbEvnts" the ref's could be held in a
collection or array.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top