Filling Excel userform in excel file automatically from vbscript

和自甴很熟 提交于 2020-01-04 04:29:48

问题


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

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