Auto_open in an .xla

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,197
We have a custom sort routine activated by a double click

Code:
Sub Auto_Open()
    On Error Resume Next
    Application.OnDoubleClick = "AutoSort"
    
End Sub

It used to sit in a module in each workbook, but I modified it to work from personal.xls. When I moved it to a .xla addin file it stopped, so I'm figuring that opening a .xls doesn't trigger the auto_open event. Is the case? If so, is there another way, if not, any idea what I'm doing wrong?

Cheers,
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Not sure but maybe try using a Workbook_Open Event ... should do the same and is the newer technology for Excel VBA ... if that doesn't work we'll really start scratching our heads.

Alex.
 
Upvote 0
Hi,
Try this:
Rich (BB code):
<font face=Courier New>
' Code should be in ThisWorkbook (class) module of the personal.xls or XLA
Dim WithEvents Apps As Application

Private Sub Workbook_Open()
  Set Apps = Application
  ' Redefine double click event to AutoSort() subroutine of standard module
  Apps.OnDoubleClick = "'" & ThisWorkbook.Name & "'!AutoSort"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Set Apps = Nothing
End Sub</FONT>
Vladimir
 
Upvote 0
Without hidden OnDoubleClick member approx the same (but not exactly the same) result could be achieved:
Rich (BB code):
<font face=Courier New>
' Code should be in ThisWorkbook (class) module of the personal.xls or XLA
Dim WithEvents Apps As Application

Private Sub Apps_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
  ' Put your code for DoubleClick event
  MsgBox "Your sorting..."
End Sub

Private Sub Workbook_Open()
  Set Apps = Application
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Set Apps = Nothing
End Sub</FONT>
 
Upvote 0
Looks promising - will give this a try later today if possible. It's a work thing, but something of a side project!

Cheers for the replies.
 
Upvote 0
If you do use Workbook open event of the Addin, which should work, then also put in the reset code to disable it in the Addinuninstall event other wise the double click event will always call this addin.
 
Upvote 0
Not sure that AddInUninstall event is required if BeforeClose event is used. Uninstalling of AddIn means the unloading which causes BeforeClose event where resetting code could be.

But agree that using of hidden OnDoubleClick event requires the correct resetting of this application event, here is the fixed code:
Rich (BB code):
<font face=Courier New>
' Code should be in ThisWorkbook (class) module
Private Sub Workbook_Open()
  ' Redefine double click event to AutoSort() subroutine of standard module
  Application.OnDoubleClick = "'" & ThisWorkbook.Name & "'!AutoSort"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Application.OnDoubleClick = ""
End Sub</FONT>
Please take into account that usage of hidden VBA members is not recommended.

Vladimir
 
Last edited:
Upvote 0
We used the code in reply #4, which seems to work (after I changed all the 'activesheet' references to 'sh'. Do any of these new provisos apply in that situation? I'm assuming not, but I'd appreciate confirmation.

Thanks for your help so far!
 
Upvote 0
I confirm that all is correct in code of post #4.
You can also use variable Sh for choosing the exact sheets where your sorting will play.
Cheers,
Vladimir
 
Upvote 0
For info only, but I noticed the link to the code seems to 'break' when you edit it. Obviously this isn't a problem.

All is looking good now, Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,229
Members
448,879
Latest member
VanGirl

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