Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling Excel userform in excel file automatically from vbscript

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?

like image 831
Zuzu JH Avatar asked Jun 12 '26 20:06

Zuzu JH


1 Answers

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

like image 139
Ahmad Avatar answered Jun 14 '26 08:06

Ahmad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!