问题描述
我有一个Excel文件,该文件充满了宏以及可以帮助用户在此Excel文件中正确填充数据的函数和用户窗体.我需要编写一个访问用户窗体之一的VBScript.自动填充.我知道如何调用工作簿中确实存在的VBA宏.
I have an Excel file that is full of macro and functions and userforms that help the user to fill the data correctly in this Excel file. I need to write a VBScript that accesses one of the userforms. Fills it automatically. I know how to call a VBA macro that does exist in a workbook.
objExcel.Application.Run"'CAM0500040F10_SW_Quality_Assurance_Report_Template (05-11-2012).xlsm'!new_document()"
但是现在我需要能够从我的代码中填写用户表格.有办法吗?
but now I need to be able to fill a userform from my code. is there a way to do that?
推荐答案
一种方法是使用 SendKeys
这样的功能
One way to do that is to use SendKeys
function like this
SendKeys "Value1{Tab}Value2{Return}"
上面的代码将用字符串"Value1"填充第一个字段,然后焦点将转移(由于发送了TAB),然后第二个字段将获得"Value2".如果您需要按Enter键,也可以这样做.
The above code will fill the first field with the string "Value1" then the focus will shift (because of TAB being sent) then the second field will get "Value2". If you need to press an Enter key then you can do that too.
您可以在此处阅读有关SendKeys函数,可以键入哪些键的更多信息,等等. http://msdn.microsoft.com/zh-cn/library/office/aa202943(v = office.10).aspx
You can read more about SendKeys function, what keys you can type, and so on herehttp://msdn.microsoft.com/en-us/library/office/aa202943(v=office.10).aspx
这篇关于从vbscript自动在Excel文件中填写Excel用户窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!