问题
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?
回答1:
One way to do that is to use SendKeys
function like this
SendKeys "Value1{Tab}Value2{Return}"
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.
You can read more about SendKeys function, what keys you can type, and so on here http://msdn.microsoft.com/en-us/library/office/aa202943(v=office.10).aspx
来源:https://stackoverflow.com/questions/13228146/filling-excel-userform-in-excel-file-automatically-from-vbscript