+ Reply to Thread
Results 1 to 3 of 3

Copy Sheet with Command Button to new Worbook and assign macro in new workbook

  1. #1
    Registered User
    Join Date
    01-03-2005
    Posts
    35

    Copy Sheet with Command Button to new Worbook and assign macro in new workbook

    Hi,

    I have a workbook ("Testing.xls") with a worksheet ("TestSheet" - Sheet1)

    This worksheet contains a command button ("Button 1")

    This command button runs a macro ("Validate") which is contained in that worksheet

    Essentially, I want to copy the whole sheet to a new workbook, and be able to run the "Validate" macro in that new file.

    I can successfully copy the sheet, and the "Validate" macro it contains to a new workbook.

    However, I can't seem to get the command button in the new workbook to point to the new workbook. It always seems to point back to "Testing.xls"

    I have the following code:

    PHP Code: 
    Sub CopySheetWithCmndButton()

    WS "TestSheet"
    Worksheets(WS).Shapes("Button 1").OnAction "Sheet1.Validate"
    Worksheets(WS).Copy
    ActiveWorkbook
    .Worksheets(WS).Shapes("Button 1").OnAction ActiveWorkbook ".Sheet1.Validate"

    End Sub 
    This produces a runtime error 438 (Object doesn't support this property or method) on the following line:
    PHP Code: 
    ActiveWorkbook.Worksheets(WS).Shapes("Button 1").OnAction ActiveWorkbook ".Sheet1.Validate" 
    Thanks in advance for any help you can provide!

  2. #2
    Registered User
    Join Date
    01-03-2005
    Posts
    35

    Re: Copy Sheet with Command Button to new Worbook and assign macro in new workbook

    OK, I've been working on this some more and replaced the code by adding the following:

    PHP Code: 
    Private Sub CommandButton1_Click()
    Application.Run ("Sheet12.Validate")
    End Sub 
    There are two sheets I'm doing this with.
    Sheet1, which I used the above code on and it works fine
    Sheet12 is where I'm having a problem, and I keep getting the following message, where it's unable to call the macro

    Run-time error '1004':

    Method 'Run' of of _Application failed

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Copy Sheet with Command Button to new Worbook and assign macro in new workbook

    can you edit & use Code tags not PHP
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1