excel copy and paste in Windows Search

冷暖自知 提交于 2019-12-13 18:30: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 

回答1:


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



来源:https://stackoverflow.com/questions/23372662/excel-copy-and-paste-in-windows-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!