Why can't send hotkey Ctrl? - vba

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"

Related

Save an active notepad at a specific folder using sendkeys

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

Sending an image in whatsapp web using VBA

Does someone know how to add a picture in an whatsapp web conversation using VBA?
Preferably not as an attachment, but directly in the message.
I've reached a point where the code gets me to open the whatsapp web url, finds the contact to which I want to send the message and places the cursor in the message box, but I couldn't find out yet how to paste the image i've copied or even how to attach a picture inside my machine.
As the image I want to paste and send is a print of some of the worksheet's cells, when I write the code as to make it run "ctrl v" it pastes as a text, not as an image as I want.
My code so far:
Sub Send_whats()
Sheets("Current summary").Select
Dim text As String
Dim contact As String
text = "Hi! Here goes a summary of your order"
contact = Cells(6, 3)
If contact = "" Then
MsgBox "Attention, contact is blank!"
Exit Sub
End If
Range("A1:H26").Copy
ActiveWorkbook.FollowHyperlink Address:="https://web.whatsapp.com/"
Application.Wait (Now + TimeValue("0:00:07"))
Call SendKeys("{TAB}", True)
Application.Wait (Now + TimeValue("0:00:05"))
Call SendKeys(contact, True)
Application.Wait (Now + TimeValue("0:00:03"))
Call SendKeys("{TAB}", True)
Application.Wait (Now + TimeValue("0:00:02"))
Call SendKeys("{TAB}", True)
Application.Wait (Now + TimeValue("0:00:02"))
Call SendKeys("{TAB}", True)
Application.Wait (Now + TimeValue("0:00:03"))
Call SendKeys("^(V)", True) 'here is where it goes wrong!
Application.Wait (Now + TimeValue("0:00:03"))
Call SendKeys(text, True)
Application.Wait (Now + TimeValue("0:00:03"))
Call SendKeys("Enter", True)
End Sub
I appreciate any help! Thanks!

SendKeys in Powerpoint VBA

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

"Save as other" in pdf by vba

I am trying to create a VBA macro to copy data from a PDF file to an Excel file but the data always merges into 1 column instead of 2 columns same as pdf file.
It is difficult to get data for next steps.
So, I would like to use tab "Save as other" ->Text in Pdf file to save file as txt file with 2 columns. I use SendKeys "%fhx" to show Save as dialog but I can't change the path and file name.
Please help me to solve this.
The code is as follows:
Do While filepdf <> ""
task = Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe " & filename, 1)
Application.Wait Now + TimeValue("00:00:2")
SendKeys "%fhx" AppActivate (task) --- I dont know how to select Save as dialog to change path and file name ---
SendKeys "%s" Application.Wait Now + TimeValue("00:00:2")
SendKeys "%{F4}", True
filepdf = Dir(path & "*.pdf")
Loop
Two disclaimers before my answer:
I do not have Acrobat Reader, that's why I have used Notepad.exe. But the idea is the same, you will manage to adapt it.
Sending keys is not a good practise in general. But everyone uses it, so...
That's the code, the comments are hopefully explanatory.
You should find a way to put it in your loop.
Have fun:
Option Explicit
Public Sub TestMe()
Dim task As Variant
task = Shell("C:/Windows/Notepad.exe", 1)
AppActivate task
'save as
SendKeys "%fa", True
'name in the save as
SendKeys "vityata.txt", True
'press enter
SendKeys "{ENTER}", True
'exit notepad
SendKeys "%fx", True
End Sub
Edit:
If you want to change the destionation path, then change it like this:
'name in the save as
SendKeys "C:\Users\lili\ivanova\ale\new\vityata.txt", True
I tried the below code and found that it was ok :
Sub SaveAsPdf()
Dim task
task = Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe " & namepdf, 1)
SendKeys "%fhx"
AppActivate (task)
SendKeys nametxt, True
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{ENTER}"
SendKeys path, True
SendKeys "{ENTER}"
SendKeys "%s"
End sub

VBA pass cell value to Print dialogue box

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.