使用下拉列表中的值来保存Excel工作簿(使用VBA代码)

我是新来的macros,但有一些基本的想法是如何工作,或像写能够写VBA的小代码。

是否有可能在VBA代码中添加一些预定义的值,这些值可以用作下拉值,以后可以使用,因为每个谷歌有两种types的响应,例如“是的,我们可以使用它”和其他一些说'它的不可能'。

我正在试图创build一个报告。 我必须用一些值来保存它

1.预定义的值,如(“Analysis_Report”将是常数值)
2. DropDown值(“Cluster1”,“Cluster2”,“其他”) – 无法获取它
3.date和时间戳
4. InputBox(“UserName”)

但我不能设置下拉(尝试ComboBox)我的macros。 如果有人能帮我纠正我的代码,那真的很感激。 🙂

下面给出了我使用的macros的一部分供您参考

Sub ImporttoNew_WorkBook_and_Close () Dim DT As String Dim wbNam As String Dim Path Dim Cluster Dim UserName Workbooks.Add wbName = "Analysis_Report" DT = Format(CStr(Now), "yyyy_mm_dd_hh_mm_ss") Path = InputBox("Enter Path ", "Enter value") & "\" UserName = "_" & InputBox("Type your Name", "Enter value") Cluster = ComboBox1.List = Array("Cluster1", "Cluster2", "Other") **'Not Working** ActiveWorkbook.SaveAs Filename:=Path & Cluster & wbName & DT & UserName ActiveWorkbook.close MsgBox "Document saved" End Sub 

提前致谢。 🙂

combobox的问题在以下行中:

 Cluster = ComboBox1.List = Array("Cluster1", "Cluster2", "Other") **'Not Working** 

您必须首先将群集设置为您的combobox,然后分配值:

 Set Cluster = Tabelle1.ComboBox1 'change Tabelle1 to the Codename of the worksheet with your combobox1 in it Cluster.List = Array("Cluster1", "Cluster2", "Other")