Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Workbook properties code in the xla addin

I have to make code applicable to the workbook.
Like workbook_beforeprint code.
Now, after i have made the code work well,
i want to save the workbook as an addin
so that the code that i have written will be applicable to all
the workbook that will be open after the addin is loaded.
Is there any tips for that
Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Workbook properties code in the xla addin

On Apr 22, 1:47*pm, Subodh wrote:
I have to make code applicable to the workbook.
Like workbook_beforeprint code.
Now, after i have made the code work well,
*i want to save the workbook as an addin
so that the code that i have written will be applicable to all
the workbook that will be open after the addin is loaded.
Is there any tips for that
Thanks in advance.


You can use application level event application_workbookbeforeprint(Wb
As Workbook, Cancel As Boolean).For this you have to use class
mdule.Can get the details from Microsoft Site.If you need I can give
the link after a while.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Workbook properties code in the xla addin

On Apr 22, 2:11*pm, Javed wrote:
On Apr 22, 1:47*pm, Subodh wrote:

I have to make code applicable to the workbook.
Like workbook_beforeprint code.
Now, after i have made the code work well,
*i want to save the workbook as an addin
so that the code that i have written will be applicable to all
the workbook that will be open after the addin is loaded.
Is there any tips for that
Thanks in advance.


You can use application level event application_workbookbeforeprint(Wb
As Workbook, Cancel As Boolean).For this you have to use class
mdule.Can get the details from Microsoft Site.If you need I can give
the link after a while.


The link is http://www.tek-tips.com/faqs.cfm?fid=4195
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Workbook properties code in the xla addin

On Apr 22, 2:26*pm, Javed wrote:
On Apr 22, 2:11*pm, Javed wrote:

On Apr 22, 1:47*pm, Subodh wrote:


I have to make code applicable to the workbook.
Like workbook_beforeprint code.
Now, after i have made the code work well,
*i want to save the workbook as an addin
so that the code that i have written will be applicable to all
the workbook that will be open after the addin is loaded.
Is there any tips for that
Thanks in advance.


You can use application level event application_workbookbeforeprint(Wb
As Workbook, Cancel As Boolean).For this you have to use class
mdule.Can get the details from Microsoft Site.If you need I can give
the link after a while.


The link ishttp://www.tek-tips.com/faqs.cfm?fid=4195

Thanks Javed.
I tried the link
But it didn't worked.
I am using excel 2007 and XP
This is what i did
Made a new microsoft excel file (Macro Enabled)
Inserted a class module
Pasted following code in the class module

Public WithEvents xlapp as Application

Public Sub xlapp_WorkbookOpen(ByVal Wb As Workbook)
MsgBox " Testing Trap Events! "
End Sub

Named the class module as ClsAppEvents (Don't know if it was needed as
i think these names don't matter)

Again, I made a new module file (standard) renamed it as TrapAppEvents
and typed the following code in it

Public xlApplication As New ClsAppEvents

Public Sub TrapApplicationEvents()
Set xlApplication.xlapp = Application
End Sub

Saved it and kept it open
Now,I expected that if i open new excel files then the message should
trigger..
But that was not the case.
Do i need some more thing to do?
Anything in the Thisworkbook Object
Or, Did i missed something.
Plz Help.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Workbook properties code in the xla addin

I'm not a master of event programming but a couple of considerations:
(1) I'm not sure if you'd be better off declaring 'as new'. Unless I
missed something I'd declare it:
Public xlApplication As ClsAppEvent
i.e., without the NEW in it and then create the object in the code.
As far as I know it's not the best practice to declare as New as
otherwise you've got no way of testing if the variable has been
instantiated although for this particular purpose the NEW could be
good enough.

(2) I think that your problem could be in firing this code of yours:
Public Sub TrapApplicationEvents()
Set xlApplication.xlapp = Application
End Sub
i.e., this code must be run before all the event trapping can happen -
if this code hasn't run you don't have your xlApplication variable
created yet and because of that it obviously can't trigger any events.
So, I think that you don't run the code in the beginning.
To test it - just run the code separately - in VBE locate this code
and run it (F5) - it would create the xlApplication variable and from
then on it should trap the events BUT bear in mind that this variable
will cease to exist if you edit the code or close the file so what you
need to do is to make sure that this code runs before you want to
start trapping the events - so, perhaps you could put it in the
Workbook_Open event of the xla file something like this:
Private Sub Workbook_Open()
Set xlApplication.xlapp = Application
End Sub
This would be then in the ThisWorkbook module of the xla file - this
way whenever the xla opens it creates your variable for event trapping
and it should be fine now.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Workbook properties code in the xla addin

On Apr 24, 2:06*pm, AB wrote:
I'm not a master of event programming but a couple of considerations:
(1) I'm not sure if you'd be better off declaring 'as new'. Unless I
missed something I'd declare it:
Public xlApplication As ClsAppEvent
i.e., without the NEW in it and then create the object in the code.
As far as I know it's not the best practice to declare as New as
otherwise you've got no way of testing if the variable has been
instantiated although for this particular purpose the NEW could be
good enough.

(2) I think that your problem could be in firing this code of yours:
Public Sub TrapApplicationEvents()
* * *Set xlApplication.xlapp = Application
End Sub
i.e., this code must be run before all the event trapping can happen -
if this code hasn't run you don't have your xlApplication variable
created yet and because of that it obviously can't trigger any events.
So, I think that you don't run the code in the beginning.
To test it - just run the code separately - in VBE locate this code
and run it (F5) - it would create the xlApplication variable and from
then on it should trap the events BUT bear in mind that this variable
will cease to exist if you edit the code or close the file so what you
need to do is to make sure that this code runs before you want to
start trapping the events - so, perhaps you could put it in the
Workbook_Open event of the xla file something like this:
Private Sub Workbook_Open()
* * *Set xlApplication.xlapp = Application
End Sub
This would be then in the ThisWorkbook module of the xla file - this
way whenever the xla opens it creates your variable for event trapping
and it should be fine now.


I am sorry
I tried the second one also.
ie. WIthout the new keyword
But it didn't work
Can't find out what the mistake was or anything i missed out.
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
how can we embed the code to the excel workbook from addin vicky Excel Programming 5 February 4th 10 09:11 AM
can we copy the code from the addin to excel workbook vicky Excel Programming 2 February 2nd 10 10:29 PM
Get Workbook Object properties without opening Workbook? ward376 Excel Programming 0 May 29th 08 05:57 AM
Changing control properties/code through code Ajit Excel Programming 3 October 18th 04 09:03 PM
Locking VBA code via Project properties but cannot save the workbook over itself Shane Excel Programming 4 July 27th 04 01:00 AM


All times are GMT +1. The time now is 09:31 AM.

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

About Us

"It's about Microsoft Excel"