+ Reply to Thread
Results 1 to 7 of 7

How to Click a Command Button from another workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    05-26-2014
    Posts
    3

    Question How to Click a Command Button from another workbook

    All

    I am relatively proficient at Excel but somewhat new to VBA so please excuse my possibly poor terminology.

    I have two separate workbooks 'A' and 'B' and I have written VBA code in workbook 'A' which successfully opens workbook 'B'. What I require is VBA code in workbook 'A' which will click/activate the Command Button in workbook 'B'. Or alternatively is there a means of automatically clicking/activating the Command Button in workbook 'B' when it is opened?

    I have read several discussions on this topic in various forums but have not found a suitable solution.

    Would appreciate any suggestions!

    Thanks
    Mark

  2. #2
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: How to Click a Command Button from another workbook

    Upload sample files

  3. #3
    Registered User
    Join Date
    05-26-2014
    Posts
    3

    Re: How to Click a Command Button from another workbook

    haroon

    I have not attached the sample files as they contain 'sensitive' information, hence I have just referred to the files as 'A' and 'B'.

  4. #4
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: How to Click a Command Button from another workbook

    You should just strip out the sensitive data - or create a sample book that is similar.

    But my guess is that you just need to run a macro - in which case (assuming it is open) skip the button clicking aspect and just go straight to running the macro.

      Application.Run "MacroBook!MacroName"
    Last edited by scottiex; 05-26-2014 at 01:02 AM.

  5. #5
    Registered User
    Join Date
    05-26-2014
    Posts
    3

    Re: How to Click a Command Button from another workbook

    ScottieX

    I have created two sample files 'A' and 'B' (refer below). I have tried your above suggestion and it didn't work, but I am not sure if I have written the code correctly.

    File 'A'
    Private Sub CommandButton1_Click()
    Workbooks.Open Filename:="C:\Mark\VBA sample\B.xlsm"
    Application.Run "B.xlsm!CommandButton1_Click"
    End Sub

    File 'B'
    Public Sub CommandButton1_Click()
    Dim row
    For row = 3 To 8
    Cells(row, 4).Value = Cells(row, 2).Value + Cells(row, 3).Value
    Next row
    End Sub
    Last edited by Mark Elkjaer; 05-26-2014 at 01:27 AM.

  6. #6
    Registered User
    Join Date
    05-26-2014
    Posts
    3

    Re: How to Click a Command Button from another workbook

    Scottie

    Since my last post I have gotten it to work. The issue was that in the 'MacroName' I had left out the sheet number.

  7. #7
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: How to Click a Command Button from another workbook

    OK, if it is solved please mark as solved and add reputation if applicable.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. use a command button to click other command buttons
    By fcharl9 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2013, 08:48 PM
  2. Need Help command button click
    By limcaitie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2013, 10:34 PM
  3. VBA Click Command Button
    By Benz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2006, 04:30 PM
  4. Command Button - On Click Event
    By sharonm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2006, 08:20 AM

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