excel 在 Windows 搜索中复制和粘贴 [英] excel copy and paste in Windows Search

查看:70
本文介绍了excel 在 Windows 搜索中复制和粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Excel 2010 和 Windows 7 专业版.我想将一个单元格内容复制到 Windows 搜索框中.我如何为此编写 VBA?

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 

推荐答案

您可以使用 Shell.Application 对象与发送一些键击一起执行此操作.

You can use the Shell.Application object to do this in conjunction with sending some key strokes.

示例:(用您喜欢的任何内容替换我的 searchString 位)

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 参考:http://msdn.microsoft.com/en-us/library/windows/desktop/bb773938%28v=vs.85%29.aspx

Shell.Application reference: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773938%28v=vs.85%29.aspx

Windows 脚本宿主 Shell 参考:http://msdn.microsoft.com/en-us/library/aew9yb99%28v=vs.84%29.aspx

Windows scripting host Shell reference: http://msdn.microsoft.com/en-us/library/aew9yb99%28v=vs.84%29.aspx

这篇关于excel 在 Windows 搜索中复制和粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆