【问题标题】:Need a little guidance with coding a button in a database workbook需要一些关于在数据库工作簿中编写按钮的指导
【发布时间】:2019-04-10 14:13:12
【问题描述】:

我在 excel 和工作表中创建了一个数据库,需要复制并填充来自数据库中某个记录的信息。我需要打开一个新的工作簿文件,文件名中包含个人姓名,工作簿中填充了复制的工作表以及传输过来的一条记录中的信息。

我对在 VBA 中使用 excel 非常陌生,需要帮助。

Private Sub Create_Plan_Click()

Dim UserFilename As String
Dim FullName As String

UserFilename = Combo_Title & Txt_FirstName & Txt_MiddleInit & Txt_LastName & Combo_Suffix
FullName = Combo_Title & " " & Txt_FirstName & " " & Txt_MiddleInit & ". " & Txt_LastName & " " & Combo_Suffix


Unload Choose_User

Meal_Cat_Form.Show

End Sub

我不想显示 Meal_Cat_Form,而是想复制记录以及数据库文件中的其他工作表,并使用复制的工作表和所选记录中的信息创建一个全新的工作簿。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    这更像是一个旨在帮助而不是回答的提示

    第 1 步 - 数据所在位置的加载项信息

    Private Sub Create_Plan_Click()
    
    Dim UserFilename As String
    Dim FullName As String
    Dim dbSrcRow as long, dbSrcSht as Worksheet  ' These 2 Added
    
    UserFilename = Combo_Title & Txt_FirstName & Txt_MiddleInit & Txt_LastName & Combo_Suffix
    FullName = Combo_Title & " " & Txt_FirstName & " " & Txt_MiddleInit & ". " & Txt_LastName & " " & Combo_Suffix
    
    ' You also need to provide info as to where the data base record is
      Set dbSrcSht = "dbSheet"  ' You need to edit this
      Set dbSrcRow = 123        ' and this too
    ' Done
    
    ' I've swapped these next 2 lines around
    ' seems you need to carryout the copying before you loose/unload the data
      Meal_Cat_Form.Show  ' This will become the copy routine not a form
      Unload Choose_User
    ' Done
    
    End Sub
    

    第 2 步 - 关于哪些工作表需要复制的加载项信息

    ' You also need to provide info as to which sheets need to be copied
      Set Shts2Copy = "Sht1,Sht2,Sht3"  ' You need to edit this
    ' Done
    

    最后 - 您需要创建一个新工作簿并填写信息,然后保存

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多