简体   繁体   English

VBA中的Excel数据输入表单

[英]Excel Data entry forms in VBA

I am very new to VBA and have been searching to try to figure this out but with no luck. 我对VBA还是很陌生,一直在努力尝试解决这个问题,但是没有运气。

I am trying to make a form that pops up and has a bunch of different fields to enter and then when the form is submitted, the information is input into separate, specific cells. 我正在尝试制作一个弹出的表单,并要输入许多不同的字段,然后在提交表单时,将信息输入到单独的特定单元格中。 Also, once the information is input into the cells, it needs to be printed for our records. 同样,一旦信息输入到单元格中,则需要打印该信息以备记录。 One last thing to add is that I need some of the fields to disappear if they are empty on the form so that they do not print. 最后要添加的一件事是,如果某些字段在表单上为空,则我需要将其消失,以便不打印它们。

I have a lot of fields for this and all that I have found is how to insert into a new row. 我对此有很多字段,而我发现的所有内容就是如何插入新行。 If this can be done it would help me out a LOT. 如果能够做到这一点,将对我有很大帮助。 If anyone can point me in the right direction then I may be able to figure some out on my own I am fairly literate in HTML so I am able to do some coding. 如果有人可以指出正确的方向,那么我也许可以自己弄清楚一些东西,因为我相当懂HTML,因此可以进行一些编码。

The fields I have to enter: 我必须输入的字段:

Deposited By:
Number of Deposits:
Total Checks:
Electronic Deposit Number:
Electronic Deposit Number:
Manual Deposit Number:
Deposit Amount:
Deposit Amount:
Deposit Amount:
Houston Depos:
Dallas Depos:
Austin Depos:
Houston Video:
Dallas Video:
Austin Video:
Houston Records:

I will also need to add a button or make the form popup whenever the spreadsheet is opened so that the information can be entered but I believe that may be a little easier to figure out. 每当打开电子表格时,我还需要添加一个按钮或使表单弹出,以便可以输入信息,但我认为这样可能会更容易理解。 Along with pre-filling the form with the information already on the page so that it can be edited. 除了使用页面上已经存在的信息预填充表单之外,还可以对其进行编辑。

I'll try to answer a few of your questions that you had so hopefully you can write some of your own code: 我将尝试回答您的一些问题,希望您可以编写一些自己的代码:

Form popup whenever the spreadsheet is opened (Placed in the ThisWorkbook code): 每当打开电子表格时,都会弹出表单(放置在ThisWorkbook代码中):

Private Sub Workbook_Open()
    UserForm1.Show
End Sub

You can also add a button in the Worksheet and assign it a macro which uses UserForm1.Show. 您还可以在工作表中添加一个按钮,并为其分配使用UserForm1.Show的宏。

For the pre-filling the form with information from the sheet use commands like this (Placed in your UserForm code: 要使用表单中的信息预先填写表单,请使用以下命令(放置在UserForm代码中:

Private Sub UserForm_Initialize()
    txtDepositedBy.Text = Sheets("Sheet1").Range("A2")
End Sub

To print your sheets use the Sheets.PrintOut Method: 要打印工作表,请使用Sheets.PrintOut方法:

ActiveSheet.PrintOut
'or
Sheets("Sheet3").PrintOut

It has these inputs: 它具有以下输入:

.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)

To take your inputs from text boxes and other elements, you can use commands like these: 要从文本框和其他元素中获取输入,可以使用以下命令:

ActiveSheet.Range("A1").Value = TextBox1.Text
'or
Sheets("Sheet3").Range("B2").Value = ComboBox1.Text

This should cover a lot of your questions. 这应该涵盖了您的很多问题。 If you have anymore just let me know and I'll add to the post. 如果您还有其他信息,请告诉我,我将添加到帖子中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM