0

I've developed an excel addin that imports sheets into the existing one. i would like to be able to double click anywhere and be able to jump back to the first sheet.

Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, cancel As Boolean)

Sheets(1).Select
cancel = True

End Sub 

Another program writes a summary excel file. I've developed a add-in macro that when opened and run, Imports the full solution sheets and do some data manipulation. is there a way to transfer this code into the excel sheet vba project? thanks in advance

2 Answers 2

3

use workbook events

so type in ThisWorkbook code pane the following:

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Sheets(1).Select
    Cancel = True
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for your comment. but thats manually doing it. i was hoping vba could automate that step for me. because the excel sheet is generated by another program. i want to be able to load the add in, run the excel add in macro and the code would be inside the worksheets
You can code this in your addin as an Application level event. Look it up on CPearson.com
it's not a manual way at all! f you code that sub in the existing workbook where your add-in is going to add new sheets then all those new sheets will be "affected" as well. Unless the workbook is not existing and it is created by the add-in also along with all its sheets
@user3598756. Thanks. But i've tried your method and it only works when the code is pasted in my excel file vba project ThisWorkbook code pane and not my add-in vba project ThisWorkbook code pane. Ill try to explain myself abit more: Another program writes a summary excel file. I've developed a add-in macro that when opened and run, Imports the full solution sheets and do some data manipulation.
If you cannot write that code once and for all in your "summary excel file" ThisWorkbook code pane than you can have your add-in write it there via VBE object model (see This site)
-1

Press Alt+F11 to go to VBA development tab and then in the tab on the left there should be displayed your Excel worksheets.

Simply double click on the worksheets you want to apply that feature and paste the code :)

See this image for more details about where to click: https://www.extendoffice.com/images/stories/doc-excel/doc-drop-down-list-prevent-paste/doc-drop-down-list-prevent-paste-1.png

3 Comments

thanks for your comment. but thats manually doing it. i was hoping vba could automate that step for me. because the excel sheet is generated by another program. i want to be able to load the add in, run the excel add in macro and the code would be inside the worksheets.
@MarcusChua: have you tried the solution as per my answer?
Sorry, I didn't understand that way. If you want to apply that feature automatically on all worksheets use @user3598756 approach :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.