0

Hi I'm trying to modify the XmlTools.xla plugin.

I have it set up so that the UserForm already displays with everything my users need prefilled. I just need some way to programmatically click the OK button. I tried using send keys in the code snippet shown below but it does not work.

Public Sub sbShowForm()
Application.DisplayAlerts = False

ActiveSheet.Name = "Sheet555"

ActiveSheet.Cells(Rows.Count, 7).End(xlUp).Select
ActiveCell.Name = "lastCell"

ActiveSheet.Cells(1, 1) = "Is this"

frmCreateXmlList.Show
frmCreateXmlList.btnOK_Click

ActiveSheet.Cells(2, 1) = "called?"

Application.SendKeys ("{Enter}")
Application.SendKeys ("{Return}")

CreateXmlFiles.sbUserFormOKClicked
Call sbUserFormOKClicked

Application.DisplayAlerts = True

frmCreateXmlList.Hide
End Sub 'sbShowForm

I realize this request is a little goofy, but I received user requests saying that it is "too much work" to fill out the form. I know SendKeys aren't always reliable, but I'm just looking for something to get it to work.

user3768613
  • 1
  • 1
  • 4
  • I also tried frmCreateXmlList.btnOK_Click ,but that didn't seem to fix it – user3768613 Jun 23 '14 at 18:53
  • Are you sure that code is being called? – Andrew Barber Jun 23 '14 at 18:53
  • I used the debugger to step through and it looks like it is being called, but it doesn't appear to be doing anything. I updated my code (shown above). – user3768613 Jun 23 '14 at 19:05
  • hm strange but try just `{Enter}` without the (). And make sure form is active and button has focus –  Jun 23 '14 at 19:37
  • I just figured this out. My send keys were working but they were sending keystrokes to the active worksheet, not the userform. I updated the UserForm -> Properties -> ShowModal -> False When this property was set to true it would not work. I can't answer my own question yet cause I don't have enough reputation points. – user3768613 Jun 23 '14 at 19:39

1 Answers1

0

I just figured this out. My send keys were working but they were sending keystrokes to the active worksheet, not the userform. I updated the UserForm -> Properties -> ShowModal -> False

When this property was set to true it would not work. I also decided to use

Call sbUserFormOKClicked

because it should be more reliable than send keys.

user3768613
  • 1
  • 1
  • 4