RamPalav Posted May 17, 2016 Posted May 17, 2016 (edited) Hi, I want to send text into a VBA form's text field. Can someone please guide me on the autoit script that can help me. Below is the sample code that I need help on: #include <Excel.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> @ScriptDir ="D:\\AutoIT\" $sFilePath = @ScriptDir & "\ExcelForm.xlsm" Local $oAppl = _Excel_Open() ;Local $oAppl = _Excel_Open(False, Default, Default, Default, True) Local $sWorkbook = $sFilePath Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ConsoleWrite('before opening macro.........1') $oAppl.Run('mymacro') Sleep(3000) ConsoleWrite('After opening macro.........1') Send('First text') ConsoleWrite('After opening macro.........2') Send('{TAB}') ConsoleWrite('After opening macro.........3') Send('Second text') ConsoleWrite('After opening macro.........4') Send('{TAB}') Send('{Enter}') ConsoleWrite('After opening macro.........5') thanks, Edited May 17, 2016 by Melba23 Added code tags
Moderators Melba23 Posted May 17, 2016 Moderators Posted May 17, 2016 RamPalav, Please pay attention to where you post - the "Developer General Discussion" section where you started this thread is not for general support questions. I have moved it for you, but would ask you to be more careful in future. And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
junkew Posted May 17, 2016 Posted May 17, 2016 https://www.autoitscript.com/wiki/FAQ number 31 will help you FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
RamPalav Posted May 19, 2016 Author Posted May 19, 2016 Hi junkew, I refered number 31, but here my macro is not processing further. So after running macro, it openup macro, but didnot move ahead with send/sendcontrol or tabs. do i have to do any settings in excel macro?
orbs Posted May 19, 2016 Posted May 19, 2016 @RamPalav, On 5/17/2016 at 7:20 PM, RamPalav said: @ScriptDir ="D:\\AutoIT\" first, you do not assign a value to an internal AutoIt macro. it is populated automatically. remove that line. now, what you do is this: read the tutorial "Simple Notepad Automation" (in the help file, AutoIt \ Tutorials). this tutorial explains: 1) how to wait for the form to appear, instead of using Sleep(). 2) how to use the AutoIt Windows Info tool to analyze the VBA form and find the controls you need to manipulate. once you know what the controls are called, you can substitute you Send() calls with ControlSend(), which eliminate the need for tabbing and in general makes your script more robust. now for a different aspect. VBA is used to automate Excel, and you wish to use AutoIt to automate the VBA. are you seeing something odd here? how about a change of approach - make your VBA code, before calling the form, get the text to fill (from wherever AutoIt takes it) and populate the form - and perhaps you can skip the form step altogether. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
junkew Posted May 19, 2016 Posted May 19, 2016 Or use not autoit and do it fully in vba. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
junkew Posted May 19, 2016 Posted May 19, 2016 Or use not autoit and do it fully in vba. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
RamPalav Posted May 20, 2016 Author Posted May 20, 2016 The VBA files (Containing series of multiple forms) which i get is protected and not able to edit those. So I need to send the data to it along with button click to get the result and end of last form. The issue was I was able to run macro but it was not able to pass the data to text boxes, combo box, buttons etc. I found a work way around creating a new exe through C# and calling them through AutoIT. May be it is not the correct way!! Thanks for your support!
junkew Posted May 22, 2016 Posted May 22, 2016 Even if you have a protected VBA / XLS you can open a 2nd xls with VBA writing to the VBA forms. This is allways easier then messing with external exe's. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
RamPalav Posted May 26, 2016 Author Posted May 26, 2016 Finally, do not call the macro, create a button on excel and assign macro to it and click that button with mouse click and done.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now