mercredi 31 décembre 2014

Insert VBA sub into Excel Worksheet


Vote count:

0




Good day,


I am using Excel 2013 and I would like to hide and unhide my Sheets as I work with them. I spent some time Googling around and found plenty of ancient posts on forums about adding VBA to modules, but that's not quite what I'm looking for.


On a main page where I spend most of my time using data, I have a button that shows a UserForm with a list of sheets in a ListBox. I choose the Sheet from the ListBox, hit OK, and it runs the following;



Private Sub OKButton_Click()
ThisWorkbook.Sheets(JobListBox.value).Visible = xlSheetVisible
ThisWorkbook.Sheets(JobListBox.value).Activate
Unload Me
End Sub


I would like it so when I have my new sheets created via VBA, I can populate the sheet with the following subroutine;



Private Sub Worksheet_Deactivate()
Me.Visible = xlSheetVeryHidden
End Sub


If anyone can let me know how I can make a Subroutine to insert this code into my sheets, I would greatly appreciate it.


PS: My fallback method is to, of course, just copy/paste the code manually... But I would prefer to automate it if possible.



asked 1 min ago







Insert VBA sub into Excel Worksheet

Aucun commentaire:

Enregistrer un commentaire