Application.SendKeys "{PGDN}", True
Works just fine, however Application.SendKeys "{%TAB}", True and Application.SendKeys "%{TAB}", True do nothing.
How do I execute an alt-tab with sendkeys to switch windows?
Here is the code:
Application.SendKeys "{PGDN}", True
Application.SendKeys "{PGDN}", True
xreply = MsgBox("Is this page for women? Record:" & i, vbYesNo, "Gender Checker")
If xreply = vbYes Then
ActiveSheet.Range("C" & i).Value = vbYes
End If
Use this:
Sub ReturnToWindows()
Application.SendKeys ("%{TAB}")
DoEvents
End Sub
Must be run while you are in Excel rather than the VBE.
Related
I am trying to get all the buttons using queryselector and select the particular button by looping through and finding innerHTML.
After finding the particular button, when click event is passed, nothing happens.
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://www.spirit.com/"
Do Until IE.readyState = 4: Application.Cursor = xlDefault: DoEvents: Loop
Application.Wait (Now + TimeValue("00:00:03"))
IE.document.querySelector("label[for='radio-oneWay']").Click
Application.Wait (Now + TimeValue("00:00:03"))
IE.document.querySelector("input[id='flight-OriginStationCode']").Click
Set elems = IE.document.getElementsByTagName("button")
For Each elem In elems
If (elem.innerHTML) = " Aguadilla, Puerto Rico (BQN) " Then
elem.Click
Exit For
End If
Next elem
The two airport boxes can be assigned by simulating input using SendKeys then the click event will be triggered. The date-input and other textbox will be set separately. Here is the code which implements this function:
Private Sub CommandButton1_Click()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://www.spirit.com/"
Do Until IE.readyState = 4: Application.Cursor = xlDefault: DoEvents: Loop
Application.Wait (Now + TimeValue("00:00:03"))
IE.document.querySelector("label[for='radio-oneWay']").Click
Application.Wait (Now + TimeValue("00:00:03"))
Set elems = IE.document.getElementsByTagName("button")
Set txt1 = IE.document.getElementsByName("originStationCode")(0)
txt1.Focus
SendKeys ("BQN")
Application.Wait (Now + TimeValue("00:00:01"))
Set txt2 = IE.document.querySelector("input[id='flight-DestinationStationCode']")
txt2.Focus
SendKeys ("BDL")
Application.Wait (Now + TimeValue("00:00:01"))
Application.Wait (Now + TimeValue("00:00:01"))
IE.document.querySelector("input[id='flight-Date']").Value = "2020/10/09-2020/10/19"
IE.document.querySelector("input[id='promoCode']").Value = "xx"
IE.document.querySelector("button[type='submit']").Click
End Sub
Result:
All my sendkeys execute properly and the document saves and closes but then the next document does not Open. Before I added the sendkeys, the documents in the DIR would each open but now the next document will not. What am I doing wrong?
Sub Password()
Dim CustRow, LastRow As Long
Dim Password As String
Dim fileName As Variant
With Sheet1
LastRow = .Range("C9999").End(xlUp).Row
fileName = Dir("C:\State_K-1_Info\Password\*.pdf")
Do While fileName <> ""
CreateObject("Shell.Application").Open ("C:\State_K-1_Info\Password\" & fileName)
Application.Wait Now + 0.00005
For CustRow = 2 To LastRow
Password = .Range("C" & CustRow).Value
Application.SendKeys "{F6}", True
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.Wait Now + 0.00001
Application.SendKeys Password, True
Application.Wait Now + 0.00002
Application.SendKeys "(~)", True
Application.Wait Now + 0.00001
Application.SendKeys Password, True
Application.Wait Now + 0.00002
Application.SendKeys "(~)", True
Application.Wait Now + 0.00001
Application.SendKeys "(~)", True
Application.Wait Now + 0.00001
Application.SendKeys "^(s)", True
Application.Wait Now + 0.00001
Application.SendKeys "%{F4}", True
Application.Wait Now + 0.00001
fileName = Dir
Next CustRow
Loop
End With
End Sub
I'm struggling to create my first macro in VBA, I try to make simple macro which will switch button in each minute to present different data.
Right now I'm really frustrated, because each time I change something I receive different error, for sure I have issues with references to worksheet which I want to choose. Currently I get error "loop without do" and when I'm deleting loop, I get compile error "expected end with".
Please find my "work" below, and please let me how to make it work.
Public Sub Switch()
Do
For Each ws In ThisWorkbook.Worksheets
ControlBoard.Activate
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = True
.SlicerItems("YY").Selected = False
.SlicerItems("ZZ").Selected = False
Application.Wait Now("00:01:00")
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = False
.SlicerItems("YY").Selected = True
.SlicerItems("ZZ").Selected = False
Application.Wait Now("00:01:00")
End With
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = False
.SlicerItems("YY").Selected = False
.SlicerItems("ZZ").Selected = True
Application.Wait Now("00:01:00")
End With
Loop
End Sub
Ok, now I change it a bit and I get Run time error 13 (type mismatch) and I get debug on first line - Application.Wait Now("00:01:00")
Public Sub Switch()
Dim DashBoard As Sheet3
Do
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = True
.SlicerItems("YY").Selected = False
.SlicerItems("ZZ").Selected = False
Application.Wait Now("00:01:00")
End With
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = False
.SlicerItems("YY").Selected = True
.SlicerItems("ZZ").Selected = False
Application.Wait Now("00:01:00")
End With
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = False
.SlicerItems("YY").Selected = False
.SlicerItems("ZZ").Selected = True
Application.Wait Now("00:01:00")
End With
Loop
End Sub
I have solved type mismatch by adding + TimeValue
Application.Wait Now + TimeValue("00:01:00")
But slicer doesn't behave, as I want it. It gets me at beginning ("XX") true but further on it ticking ("YY") true and ("XX") still remains, as true, can you help me to solve it?
OK I have solved this by putting True statement in first line, it's freeze from time to time but it works, can you let me know, if it's possible to add switch off key, to avoid esc+esc exit?
Public Sub Switch()
Dim DashBoard As Sheet3
Do
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("XX").Selected = True
.SlicerItems("YY").Selected = False
.SlicerItems("ZZ").Selected = False
Application.Wait Now + TimeValue("00:00:10")
End With
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("YY").Selected = True
.SlicerItems("XX").Selected = False
.SlicerItems("ZZ").Selected = False
Application.Wait Now + TimeValue("00:00:10")
End With
With ActiveWorkbook.SlicerCaches("Slicer_Project1")
.SlicerItems("ZZ").Selected = True
.SlicerItems("XX").Selected = False
.SlicerItems("YY").Selected = False
Application.Wait Now + TimeValue("00:00:10")
End With
Loop
End Sub
I have this problem where SendKeys works only at times. I am not able to figure when it works either. I tried using the following commands,
Application.SendKeys "{ENTER}", True
Application.SendKeys "~"
I have also tried adding a timer before as well as after the sendkey command. i tried changing True to False.. but nothing seems to work.
lbr = Sheet2.Range("a" & lb).Value
IE.Document.getElementById("sample-1").Value = lbr
IE.Document.getElementById("sample-1").Focus
'Application.SendKeys "~"
Application.SendKeys "{ENTER}", True
'Application.SendKeys "{ENTER}"
'Application.SendKeys "{ENTER}", False
Can someone please suggest a solution or an alternative.
Thank you..
So I've been searching everywhere for a way to temporarily show a text box in excel. Basically, what I'm trying to show a text for 5 seconds after the user clicks the button. I don't want anyone to "do the code for me" but instead give me pointers. The user clicks a button to switch language. When that button is pressed, I want a message to appear saying: "All values have been reset". My question is the following: Is there a function in excel-vba that show a textbox for a certain amount of time before disappearing or turning his visibility value to false?
All the rest of the code to switch the language has already been done I'm really only looking to find the function that turns off the visibility after time. (a timer or i don't know)
I doubt showing the code I have so far would help but if you wish to see it, indicate it in the comments.
Thank you SO
Here is my code so far:
Private Sub Ok_Click()
startTimer
Unload Me
End Sub
Sub startTimer()
Application.OnTime Now + TimeValue("00:00:01"), "NextTime"
End Sub
Sub NextTime()
If Sheet3.Range("B5") = 0 Then reset
If Sheet3.Range("B5") = 0 Then Exit Sub
Sheet3.Range("B5").Value = Sheet3.Range("B5").Value - TimeValue("00:00:01")
startTimer
End Sub
Sub reset()
Sheet3.Range("B5") = ("00:00:05")
End Sub
Consider:
Sub MAIN()
Call BoxMaker
DoEvents
DoEvents
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 5
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
ActiveSheet.Shapes("SPLASH").Delete
End Sub
Sub BoxMaker()
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 217.5, 51#, _
482.25, 278.25).Select
Selection.Name = "SPLASH"
Selection.Characters.Text = "Please Wait for Macro"
With Selection.Characters(Start:=1, Length:=21).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 36
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
End Sub