0

Any way to use vba to add vba code on a worksheet?

I need to create a worksheet with a button on it that allows people to click on the button to select the report they have and then add a double click function on their report page. And I need to share this file on the server for everyone's use.

After they run this file, they are able to double click on their report page's Range("A1:A10") and jump to sheet2 and auto-filtered by the values of the cells in Range("A1:A10").

I can do the code, just don't know how to add it on their workbook's sheet.

I have been searching for days to find the answer for writing vba by vba, but just no luck.

joey yao
  • 1
  • 1
  • Possible duplicate of [How to add a button programmatically in VBA next to some sheet cell data?](https://stackoverflow.com/questions/4559094/how-to-add-a-button-programmatically-in-vba-next-to-some-sheet-cell-data) – teylyn Dec 19 '17 at 01:35
  • Sounds like you could create it as an add-in. – Carol Dec 19 '17 at 01:36
  • I didn't make it clear. It needs to be idiot proof. Add-in is "too much technique" for them. Ideally, They just need to click a button on my file, select their file on their computer and click Ok, then the function is added on their reports. My problem is I know how to write these code, but don't know how to write it on their reports' sheet(1)'s vba editing section and save it. It's (Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean). It needs to be written on the sheet itself. – joey yao Dec 19 '17 at 04:07
  • I just need to open their reports, sheet(1)'s vba editing section, paste those code, and that's it. But how to do it by vba? – joey yao Dec 19 '17 at 04:11
  • "I just need to open their reports, sheet(1)'s vba editing section, paste those code, and that's it.": Well this would be possible using [Workbook.VBProject Property](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/workbook-vbproject-property-excel). But it also is a really big security issue. Thats why this [is denied by default](https://support.microsoft.com/en-us/help/282830/programmatic-access-to-office-vba-project-is-denied). – Axel Richter Dec 19 '17 at 06:58

0 Answers0