Reputation: 27
I am using Excel 2010 and Windows 7 Pro. I want to copy one cell content into Windows Search box. How do I write a VBA for that?
Sub CopytoSearchWindow()
'CopytoSearchWindow Macro ' '
sCell = Range(Application.InputBox(Prompt:="Pick the Cell", Type:=8)).Value
Upvotes: 1
Views: 462
Reputation: 3310
You can use the Shell.Application object to do this in conjunction with sending some key strokes.
Example: (replace my searchString bit with whatever you like)
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub searchExample()
Dim searchCell As Range
Dim shellApp As Object
Dim wshShell As Object
On Error Resume Next 'to catch if user presses cancel
Set searchCell = Application.InputBox(Prompt:="Pick the Cell", Type:=8)
On Error Goto 0
If searchCell Is Nothing Then Exit Sub
Set shellApp = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
shellApp.FindFiles
Sleep 500
wshShell.SendKeys searchCell.Value & "{enter}"
End Sub
Shell.Application reference: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773938%28v=vs.85%29.aspx
Windows scripting host Shell reference: http://msdn.microsoft.com/en-us/library/aew9yb99%28v=vs.84%29.aspx
Upvotes: 1