+ Reply to Thread
Results 1 to 10 of 10

Cannot assign macro to button....HELP!!!

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2007
    Posts
    38

    Cannot assign macro to button....HELP!!!

    This works

    Sub Macro1() 
    Application.CommandBars.FindControl(ID:=1849).Execute 
    Application.SendKeys ("%t %h {DOWN} %n {ESC}") 
    End Sub

    And this doesn't

    Private Sub CommandButton5_Click() 
    Application.Dialogs(xlDialogValueFind).Show 
    Application.SendKeys ("%t %h {DOWN} %n {ESC}") 
    End Sub

    Any ideas would be gratefully received

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try to avoid Sendkeys. What exactly do you want to do?
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    04-25-2007
    Posts
    38
    Hi Roy

    I was trying to assign some code to a button so that it popped up with the "find" dialog box (i.e. CTRL-F), but in addition to this that it defaulted to searching the workbook and not the worksheet as would be normal...........hence the sendkeys code.

    I could use the above macro but when I assigned it to a button of any type it failed?!??!

    I then decided to forget about the button and give it a shortcut key of CTRL-F but after doing that it didn't behave as it should. Whenever I did a search using CTRL-F it would give me about 50% of the results I should have got?????

    I decided to give up on that idea as I was now in the twilight zone so I'm now looking for a neat solution to searching the whole workbook if you have any ideas????

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Ctrl F should display the Find Dialog anyway.

    This line should display the Dialog

    Application.Dialogs(xlDialogFormulaFind).Show
    Last edited by royUK; 08-08-2007 at 05:15 AM.

  5. #5
    Registered User
    Join Date
    04-25-2007
    Posts
    38
    Hi Roy

    Thanks but as you can see above, that's what I used....

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by fry
    Hi Roy

    Thanks but as you can see above, that's what I used....
    I don't understand your problem, that line of code works.

+ 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