Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default write vba to a worksheet via a macro

i have a macro that deletes tabs a, b, c, and then re-creates them with the
current information i enter into tab d.

i have a worksheet (beforedoubleclick) procedure that i want to incorporate
into worksheet b...but the procedure is deleted each time the macro is run
because the deletion of worksheet b is part of the macro.

is there a way for the macro to write the beforedoubleclick procedure to
worksheet b after it has been deleted and re-added?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default write vba to a worksheet via a macro

Hi
You probably need to use the SheetBeforeDoubleClick within the
ThisWorkbook module. This gives you the option of passing it the sheet
where the doubleclick applies.
Something like:

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal
Target As Range, Cancel As Boolean)
If Sh.Name = "b" then
'your current code
endif
End Sub

regards
Paul

On Jan 4, 9:06*pm, joemeshuggah
wrote:
i have a macro that deletes tabs a, b, c, and then re-creates them with the
current information i enter into tab d. *

i have a worksheet (beforedoubleclick) procedure that i want to incorporate
into worksheet b...but the procedure is deleted each time the macro is run
because the deletion of worksheet b is part of the macro.

is there a way for the macro to write the beforedoubleclick procedure to
worksheet b after it has been deleted and re-added?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default write vba to a worksheet via a macro

You can have code that writes code, but there are easier ways...

Instead of deleting the worksheet, just clear (or clearcontents) the cells.

with worksheets("A")
.cells.clearcontents 'remove values and formulas
'or
.cells.clear 'remove all the formatting, too.
'or even limit it to a range
.rows("3:99").clear 'clearcontents
'if you wanted to keep headers/footers/filters/...
End with

Or you could create a template sheet (hide it) and use that as the basis for the
new sheet. That template would have everything you need--including the event
procedures.

Dim NewSheet as worksheet

with worksheets("a-sheet-template")
.visible = xlsheetvisible
.copy _
after:=sheets(sheets.count)
set NewSheet = activesheet 'new sheet based on template
.visible = xlsheethidden
end with

'and do stuff to the NewSheet Variable
newsheet.name = "A"

====


But if you want, you can visit Chip Pearson's site:
http://www.cpearson.com/excel/vbe.aspx


joemeshuggah wrote:

i have a macro that deletes tabs a, b, c, and then re-creates them with the
current information i enter into tab d.

i have a worksheet (beforedoubleclick) procedure that i want to incorporate
into worksheet b...but the procedure is deleted each time the macro is run
because the deletion of worksheet b is part of the macro.

is there a way for the macro to write the beforedoubleclick procedure to
worksheet b after it has been deleted and re-added?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default write vba to a worksheet via a macro

thanks!!!

"Dave Peterson" wrote:

You can have code that writes code, but there are easier ways...

Instead of deleting the worksheet, just clear (or clearcontents) the cells.

with worksheets("A")
.cells.clearcontents 'remove values and formulas
'or
.cells.clear 'remove all the formatting, too.
'or even limit it to a range
.rows("3:99").clear 'clearcontents
'if you wanted to keep headers/footers/filters/...
End with

Or you could create a template sheet (hide it) and use that as the basis for the
new sheet. That template would have everything you need--including the event
procedures.

Dim NewSheet as worksheet

with worksheets("a-sheet-template")
.visible = xlsheetvisible
.copy _
after:=sheets(sheets.count)
set NewSheet = activesheet 'new sheet based on template
.visible = xlsheethidden
end with

'and do stuff to the NewSheet Variable
newsheet.name = "A"

====


But if you want, you can visit Chip Pearson's site:
http://www.cpearson.com/excel/vbe.aspx


joemeshuggah wrote:

i have a macro that deletes tabs a, b, c, and then re-creates them with the
current information i enter into tab d.

i have a worksheet (beforedoubleclick) procedure that i want to incorporate
into worksheet b...but the procedure is deleted each time the macro is run
because the deletion of worksheet b is part of the macro.

is there a way for the macro to write the beforedoubleclick procedure to
worksheet b after it has been deleted and re-added?


--

Dave Peterson
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How write Macro to save worksheet to a RELATIVE address Barry Excel Discussion (Misc queries) 10 May 1st 08 08:24 PM
Can I record or write a macro to send a worksheet via Outlook? Catherine Excel Discussion (Misc queries) 1 September 14th 05 04:15 AM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
Write to One Worksheet Only ? MAS Excel Programming 1 May 25th 05 08:01 PM
IF then write new worksheet/book Don Hansford[_2_] Excel Programming 0 April 2nd 04 04:24 PM


All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"