i'm trying to copy screen info from 5250 green screen application, paste into text file then save it into a specific path location (C:\Desktop\testing).
Sub Savetxt()
AppActivate 5250Screen
SendKeys "%", True
SendKeys "EC", True
Call Shell("NOTEPAD.EXE", 1) 'open notepad
SendKeys "^v", True 'paste to notepad
SendKeys "^s", True 'save notepad
Item.SaveAs "C:\Desktop\testing" & filename & ".txt", olTXT
SendKeys "{enter}", True
SendKeys "%{F4}", True
End Sub
Can anyone pls explain me how to use SendKeys in PowerPoint VBA.
Sub SK()
SendKeys ("%"), True ' Alt
SendKeys ("H"), True ' Home Tab
SendKeys ("FC"), True ' Font Color pallet
End Sub
SendKeys in VBA will look like this, with a string of commands in double quotes. You don't need a separate statement for each command:
aShape.Select
SendKeys "+{F10}{DOWN}{DOWN}{DOWN}{DOWN}~{DEL}" & PhotoName$ & r & p & "{TAB}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{DOWN}{TAB}~", True
I am trying to use SendKeys to navigate & enter data with Internet Explorer. The first section of code has a loop during which the webpage (ending in .php) refreshes itself to get the entry in. As I'm using SendKeys once the browser is opened, I'm looking for a way to pause the script until the page is loaded and ready to receive input. I'm currently using a small time delay of 3 seconds which works well but if the browser lags, everything goes haywire.
So, is there anything that can facilitate this or at least allow me to use the GetObject command to set a current instance of Internet Explorer as an object.
AppActivate "Explorer"
Dim CCount As Integer
Dim DCount As Integer
Dim LCount As Integer
LCount = 1
CCount = 2
DCount = ActiveSheet.Range("O2").Value
Dim LoopP As Integer
LoopP = 1
For LoopP = 1 To DCount
SendKeys ActiveSheet.Range("A" & CCount).Value, True
SendKeys "{Tab}", True
SendKeys Format(ActiveSheet.Range("C" & CCount).Value, "#,###"), True
SendKeys "{Tab}", True
' Breakdown IF
If ActiveSheet.Range("K" & CCount).Value = 1 Then
SendKeys ActiveSheet.Range("D" & CCount).Value, True
Else
End If
SendKeys "{Tab}"
' Remark IF
If ActiveSheet.Range("L" & CCount).Value = 1 Then
SendKeys ActiveSheet.Range("E" & CCount).Value, True
Else
End If
SendKeys "{Tab}", True
SendKeys "{Enter}", True
CCount = CCount + 1
' While IE.Busy Or IE.readyState <> 4: DoEvents: Wend
' While IE.readyState <> 4 Or IE.Busy: DoEvents: Wend
' Do While IE.readyState <> 4: WScript.Sleep 100: Loop
Application.Wait (Now + TimeValue("0:00:01"))
Next LoopP
This is the Sub that I have built so far:
Sub Grab_Screencap()
'Open URL
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate _
Worksheets("Queue").Range("A3").Value
Application.Wait (Now + #12:00:02 AM#)
SendKeys "^p", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "{UP}", True
SendKeys "{UP}", True
SendKeys "~", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "~", True
End With
End Sub
I am sure there are much better ways to do it, but I am still on the kiddie side of the pool.
This takes a URL that I have in a spreadsheets, and then opens IE, navigates to that page, opens the Print dialogue box, selects XPS Document Writer, navigates to the pathway field, and then highlights the value.
Now I want to pass a base directory, and a file name from a cell, something like
"C:\users\user1\desktop\" & Worksheets("Queue").Range("A5").Value
Tinkering around but cant find any existing documentation that lines up with what I'm trying to do that I can comprehend.
In order to print the content of the external file (for example, C:\Temp\TestFile.txt) from Excel VBA macro you can use ShellExecute() function as shown below.
First, insert the VBA Module (e.g. Module1) and place the following declarations and Sub into that Module1:
Public Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Public Const SW_SHOWNORMAL = 1
Public Sub ShellExecuteSample()
'shown as example: it will open the text file C:\Temp\TestFile.txt
OpenFile = ShellExecute(hwnd, "open", "C:\Temp\TestFile.txt", "", "C:\", SW_SHOWNORMAL)
'this will print the content of the text file C:\Temp\TestFile.txt
PrintFile = ShellExecute(hwnd, "print", "C:\Temp\TestFile.txt", "", "C:\", SW_SHOWNORMAL)
End Sub
When called, this Sub ShellExecuteSample() will print the content and (optionally) open the text file: C:\Temp\TestFile.txt. Pertinent to your case, it could be the file specified by your string:
"C:\users\user1\desktop\" & Worksheets("Queue").Range("A5").Value
Apparently, you do not need a PrintDialog to complete this task.
Hope this may help.
So, im sure this isn't nearly the most elegant way to achieve the task, but this is what I was able to write that does what I want it to do:
Sub Grab_Screencap()
Dim i As Integer
i = 3
Do Until IsEmpty(Cells(i, 2))
'Copy Screencap Name
Sheets("Queue").Cells(i, 6).Copy
'Open URL
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate _
Worksheets("Queue").Cells(i, 2).Value
Application.Wait (Now + #12:00:02 AM#)
SendKeys "^p", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "{UP}", True
SendKeys "{UP}", True
SendKeys "~", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "~", True
SendKeys "C:\Users\Johnny\Desktop\Job Listings\"
Application.Wait (Now + #12:00:02 AM#)
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
SendKeys "+{TAB}", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "^v", True
Application.Wait (Now + #12:00:02 AM#)
SendKeys "%s", True
Application.Wait (Now + #12:00:02 AM#)
IE.Quit
End With
i = i + 1
Loop
End Sub
The 101 lesson was that SendKeys can send an entire string, not just a single key. I didnt need to merge the file name with the pathway. I just needed to drop the pathway, tab back to file name, and drop the file name, which I could copy before opening IE.
I think there is a way to do this task just by opening the print dialogue and activating print to file, but I have not tried to figure that out yet.
If send hotkey simple. It is OK:
Shell "Notepad", vbNormalFocus
SendKeys "P"
But if send hotkey has Ctrl. it not ok:
SendKeys "^P"
Why can't send hotkey Ctrl?
try lowercase p
Shell "Notepad", vbNormalFocus
Application.Wait Now + TimeValue("00:00:02")
SendKeys "^p"