在新工作表中输入用户表单数据

时间:2010-08-09 00:32:27

标签: excel-vba vba excel

每次我点击命令按钮并将工作表命名为day1,day2,day3等时,我想在新工作表中保存文本框值。我尝试了不同的方式,我不知道是否可能.i如果有人将我推向正确的方向,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

这是展示基本功能的示例代码。

Private Sub CommandButton1_Click()
Dim WB As Workbook, SH As Worksheet, FN As String

    Set WB = Workbooks.Add                      ' create a new workbook
    Set SH = WB.Sheets(1)                       ' use first sheet
    FN = "SH " & Format(Now(), "YYYY-MM-DD")    ' construct a file name from current date
    SH.[A1] = Me.TextBox1                       ' write textbox value into cell A1
    WB.SaveAs FN, xlExcel7                      ' save new workbookas Excel7 format
    WB.Close                                    ' close workbook
    Me.Hide                                     ' close dialog window
End Sub

希望这有帮助

祝你好运 - MikeD