• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using the module within any workbook

Wojciech

New Member
Hi,

I'm new to VBA, but I saw some tools I'd like to use.

So I have this simple module
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim strRange As String
strRange = Target.Cells.Address & "," & _
Target.Cells.EntireRow.Address & "," & _
Target.Cells.EntireRow.Address
Range(strRange).Select
End Sub
(links to the BeforeDoubleClick event)

The purpose is to highlight the whole row and column of the cell I double click. And it works! But only if I copy and paste it into each workbook I open... I open a lot of excel files sent over to me or found within databases, and this tool as you might imagine is fairly useless to me unless I can have it work anywhere.

Any way to achieve this? I did save it in my personal macro book, but it seems I still have to copy it over to the sheet for it to work.

Kind Regards,
Wojciech
 
Last edited by a moderator:
Since its a worksheet event, the only way is to copy paste to the file you need it in, as adding it to personal xlsb will not make it work in the file you want
 
Only time saver I'd suggest is pasting the code in ThisWorkbook Module than in each sheet which will save you the exercise of copying to each sheet module.
Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim strRange As String
strRange = Target.Cells.Address & "," & _
Target.Cells.EntireRow.Address & "," & _
Target.Cells.EntireRow.Address
Range(strRange).Select
End Sub
 
Thank you for the help.

For the record (should anyone try this macro) I made an error there, should read

Code:
PrivateSub Workbook_SheetBeforeDoubleClick(ByVal Sh AsObject, ByVal Target As Range, Cancel AsBoolean)
Dim strRange AsString
strRange = Target.Cells.Address & "," & _
Target.Cells.EntireRow.Address & "," & _
Target.Cells.EntireColumn.Address
Range(strRange).Select
End Sub

Okay, and I believe VBA allows me to make macros that I can assign to the toolbar, correct? Will those work across multiple workbooks or do they need to be copied over as well? I've seen macros that automatically unhide all sheets or all columns/rows which would be great for me to automate. It's a very annoying task (looking for hidden information)
 
Last edited by a moderator:
Back
Top