Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Copying Macros

Hi there,

I am having a problem copying a worksheet which has several macros (buttons) on it.

When I copy the worksheet, the buttons loose the link to the code I have created.

Can anyone tell me how I copy a worksheet, and keep the macros (buttons) linked to the code, without having to manual assign the code.

Thanks in Advance
[365 byte] By [NWright] at [2007-11-11 11:58:00]
# 1 Re: Copying Macros
Welcome to dev-archive :WAVE:

How do you copy it? Are you using Windows Explorer to do the copy or are you doing it through code?
Hack at 2007-11-11 17:20:57 >
# 2 Re: Copying Macros
Hi,

Thanks for your reply.

I need to do all the copying via code. Is this possible. I know how to copy the worksheet but not the macros to enable the code to still be assigned to them.

Thanks in advance
NWright at 2007-11-11 17:21:52 >
# 3 Re: Copying Macros
What code are you using to copy it?

Are you trying to copy a worksheet from within itself?
Hack at 2007-11-11 17:22:51 >
# 4 Re: Copying Macros
I have listed the code I am using below. This only moves the sheet will all information attached to it but does not copy my buttons with the assigned code.

Sheets("System 1").Select
ActiveSheet.Buttons.Add(47.25, 75.75, 97.5, 28.5).Select
ActiveSheet.Buttons.Add(47.25, 120, 97.5, 28.5).Select
ActiveSheet.Buttons.Add(48, 165.75, 97.5, 28.5).Select
ActiveSheet.Buttons.Add(48, 210.75, 97.5, 28.5).Select
ActiveSheet.Buttons.Add(49.5, 256.5, 97.5, 28.5).Select
Sheets("Editing...").Copy After:=Sheets(9)

This has been really annoying me for a while now.

Thank you in Advance
NWright at 2007-11-11 17:23:56 >
# 5 Re: Copying Macros
Can you use a binary data copy ? I mean copy the file itself without copying element by element ? or you just want to copy specified objects ?
and what r u using .. VB or VBA ? because I thing your method copy the object "button" but doesn't copy its events ..
Amahdy at 2007-11-11 17:24:56 >
# 6 Re: Copying Macros
So, is this right? You need to copy an exising Worksheet into a new worksheet within the same workbook as opposed to simply making a new copy of the entire file?
Hack at 2007-11-11 17:25:55 >
# 7 Re: Copying Macros
Hack,

You are right. That is exactly what I need to do.

I apologise for any misunderstandings, I am reletivly new to VBA.

I do believe that my code does copy the button across but like it says above not the events. This is what I need to do

Thank you in Advance
NWright at 2007-11-11 17:26:59 >
# 8 Re: Copying Macros
Does this ( http://techrepublic.com.com/5208-6230-0.html?forumID=101&threadID=215162&messageID=2195715) help?
Hack at 2007-11-11 17:28:03 >