LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Copy Code From a one excel to other through Macro

Hi,

I have excel1.xls and excel2.xls. In excel1.xls i have a certain bit of code
that i need to copy into excel2.xls. The code is for the command button i
have in excel2.xls. This code runs when i click the command button.

the code i am using to copy is:
Sub CopyModule(SourceWB As Workbook, strModuleName As String, TargetWB As
Workbook)

' copies a module from one workbook to another
' example:
' CopyModule Workbooks("Book1.xls"), "Module1", Workbooks ("Book2.xls")
Dim strFolder As String, strTempFile As String
strFolder = SourceWB.Path
If Len(strFolder) = 0 Then strFolder = CurDir
strFolder = strFolder & ""
strTempFile = strFolder & "~tmpexport.bas"
On Error Resume Next
SourceWB.VBProject.VBComponents(strModuleName).Exp ort strTempFile
TargetWB.VBProject.VBComponents(5).Import strTempFile

Kill strTempFile
On Error GoTo 0
End Sub

The code that needs to be copied is something like this..
Private Sub CommandButton1_Click()
MsgBox "hi"
End Sub

This code needs to be copied into the "Sheet1". But when i copy the code it
goes into a new module of the excel2.xls instead of Sheet1.

What is the code i should follow inorder to copy the code into the sheet1
instead of a module?

--
Senior Consultant
Kanbay Software (I) Pvt. Ltd.
http://www.kanbay.com/
 
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
Macro Copy Excel Chart Sheet to PowePoint - Mod of Jon Peltier code Frank Hayes[_2_] Charts and Charting in Excel 6 January 22nd 08 12:26 AM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed[_18_] Excel Programming 4 May 20th 04 02:08 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Excel Programming 0 May 19th 04 08:11 PM
Copy cell contents into Macro code Bob Leonard Excel Programming 2 December 1st 03 07:29 PM
Copy Sheets minus Worksheet Change Event code & Macro Buttons Bob[_36_] Excel Programming 0 October 8th 03 01:17 AM


All times are GMT +1. The time now is 03:37 PM.

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

About Us

"It's about Microsoft Excel"