English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a user form which has a text box (TextBox1) and a command button (Button1) I want whatever is in the text box to be copied into the spreadsheet (C:\Documents and Settings\Thomas Cummings\Desktop\ahsdlh) in Sheet1, cell A2. Then I want to be able to put something different into the text box and the information would be input into cell A3.

2006-10-30 07:21:48 · 7 answers · asked by Tom90 1 in Computers & Internet Programming & Design

7 answers

In design mode, you can double-click the button (Button1) to open the Visual Basic editor. When open, the screen will have a bit of computer code saying "Sub Button1_Click()", then a blank line, then an "End Sub".

On the blank line, between these two lines of code, whatever you type will be carried out when that button is clicked.

The code you're after is in the Workbook "ahsdlh", on the Sheet "Sheet1", in Cell at row 2, column 1, you want the value to be TextBox1.

This leads us to the line:
Workbooks( "ahsdlh" ).Sheets( "Sheet1" ).Cells(2, 1) = TextBox1

Which does exactly what you're after.

Hope this helps you on your journey to understanding Visual Basic for Applications.

2006-10-30 07:31:10 · answer #1 · answered by quickhare_uk 3 · 0 0

First and foremost where is the user form because that makes a BIG difference;

If its in VB then you could place an excel sheet object on the form [hidden] which you then pass parameters to.

You can get it to open the file you specified and set the active cell to a2, then get it to iterate over each cell below a2 until it finds an empty cell [the one you left off at last time]

If the user form is inside Excel that is a hell of a lot easier; you can automate openning spreadsheets easily and adding values is simple.

2006-10-30 08:45:50 · answer #2 · answered by Anonymous · 0 0

You can do that using the COM feature known as object Automation.

Create a COM object in VB that references the Excel application. Check the Visual BASIC and/or Excel online documentation for details of what API functions to call.

Make sure you do a search on "automation".

Unlike some things, this does not take many lines of code.

You are not restricted to using COM Automation from Visual BASIC or C++, even. You can do it from other languages such as Python.

2006-10-30 07:27:44 · answer #3 · answered by John C 5 · 0 0

A good way of understanding what to do is to record a macro.
It will show all the stages and you can adapt it to run under Excel itself, or for example in a Visual Studio environment. (VB VC whatever).

2006-10-30 07:25:32 · answer #4 · answered by Anonymous · 0 0

You want to add a reference to the Microsoft Excel object library and follow the MANY code examples online.

2006-10-30 07:28:19 · answer #5 · answered by Doug k 3 · 0 0

Here is a quick little snippet on how to automate Excel from VB :

http://www.freevbcode.com/ShowCode.Asp?ID=329

Good luck!

2006-10-30 07:55:56 · answer #6 · answered by Special Ed 5 · 0 0

This is too complicated to answer on here and would take a lot of time to carry out.

2016-05-22 12:07:29 · answer #7 · answered by Anonymous · 0 0

fedest.com, questions and answers