Jump to content

Send text to VBA form


Recommended Posts

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 by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

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

 

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

@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

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

 

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...