Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Create a newworksheet with VBA code and put VBA code in the new worksheet module


I need to use VBA to create a new sheet (got that part taken care of
but then I need to add a Private Sub Worksheet_Change(ByVal Target A
Range) subroutine to the page that I have just created. How do I g
about accomplishing that

--
ceshelma
-----------------------------------------------------------------------
ceshelman's Profile: http://www.excelforum.com/member.php...fo&userid=2431
View this thread: http://www.excelforum.com/showthread.php?threadid=37920

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Create a newworksheet with VBA code and put VBA code in the new worksheet module


Check this link 'Programming To The Visual Basic Editor
(http://www.cpearson.com/excel/vbe.htm

--
Nori
-----------------------------------------------------------------------
Norie's Profile: http://www.excelforum.com/member.php...fo&userid=1936
View this thread: http://www.excelforum.com/showthread.php?threadid=37920

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Create a newworksheet with VBA code and put VBA code in the new wo

This is easy if you use the Move or Copy routine when creating the new sheet.
Create a "template" sheet with your desired layout and worksheet change code.
You can hide this sheet if you desire.

Now have VBA copy this sheet for your new sheet and the code will already be
there.

Something similar to:

Sheets("YourTemplateSheet").Copy Befo=Sheets(1)

"ceshelman" wrote:


I need to use VBA to create a new sheet (got that part taken care of)
but then I need to add a Private Sub Worksheet_Change(ByVal Target As
Range) subroutine to the page that I have just created. How do I go
about accomplishing that?


--
ceshelman
------------------------------------------------------------------------
ceshelman's Profile: http://www.excelforum.com/member.php...o&userid=24314
View this thread: http://www.excelforum.com/showthread...hreadid=379209


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Create a newworksheet with VBA code and put VBA code in the new wo

Damon, will this work if you want to copy code into the "ThisWorkbook"
module of a second workbook? In other words, here's a scenario...

I have a workbook open, call it WorkBookA. I open another existing
workbook programatically or with file/open, call it WorkBookB. Can I
copy code from the ThisWorkbook module of WorkBookA to the ThisWorkBook
module of WorkBookB? Can this code be an overwrite of an existing
method in WorkBookB, say a pre-existing ThisWorkbook sub like:

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal
Target As Range, Cancel As Boolean)
.... code goes here
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Create a newworksheet with VBA code and put VBA code in the ne

Yes, it is possible. Follow the link provided by Norie for instructions. Read
the whole page so you have a good understanding of the pros and cons of
writing code with code.

I personally, will create a template with the code already present and then
add data to this template with code. I prefer the K.I.S.S. principle.

"mp112849" wrote:

Damon, will this work if you want to copy code into the "ThisWorkbook"
module of a second workbook? In other words, here's a scenario...

I have a workbook open, call it WorkBookA. I open another existing
workbook programatically or with file/open, call it WorkBookB. Can I
copy code from the ThisWorkbook module of WorkBookA to the ThisWorkBook
module of WorkBookB? Can this code be an overwrite of an existing
method in WorkBookB, say a pre-existing ThisWorkbook sub like:

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal
Target As Range, Cancel As Boolean)
.... code goes here
End Sub


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
Where?Worksheet code module or Worksheet_SelectionChange event han Kenzie Excel Worksheet Functions 4 January 30th 06 09:41 PM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM
Moved code from worksheet to module Phil Floyd Excel Programming 4 March 23rd 05 08:49 PM
Design Best Practices: Form Control Code in Worksheet or Module Bing Excel Programming 2 December 23rd 04 02:31 PM
Problem copying worksheet containing code module Basie[_2_] Excel Programming 1 September 3rd 03 12:28 AM


All times are GMT +1. The time now is 01:27 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"