我需要将用户表单的结果插入标题中,但我不知道如何将我的代码合并到最终项目中: 下面的照片和代码 < / p>
我需要标题OK按钮 1 :根据我的标题代码格式化标题,具体取决于我想要的表格,在这种情况下名为金属的表格
2 即可。之后说“金属总结”_____“&lt ;-(土壤/沉积物......等取决于检查哪个方框)
第3 即可。将输入文本的内容插入用户表单文本框。 (尚未编写代码)。
最终结果。 =对于这个特殊的表格,标题是“土壤中的金属总结,美国100大街”
感谢所有帮助!
下面的代码将结果插入A1只是暂时的 Private Sub Cancel_Click() Me.Hide 结束子
Private Sub OK_Click()
'--- Insert the correct matrix Wording ---
If Check_Soil.Value = -1 Then
Range("A1").Value = "Soil"
ElseIf Check_Sediment.Value = -1 Then
Range("A1").Value = "Sediment"
ElseIf Check_Ground_Water.Value = -1 Then
Range("A1").Value = "Ground Water"
ElseIf Check_Surface_Water.Value = -1 Then
Range("A1").Value = "Surface Water"
End If
Me.Hide
MsgBox "Completed", vbOKOnly
End Sub
Private Sub Check_Soil_Click()
'--- Checks if the Soil Button is Clicked ---
If Check_Soil.Value = True Then
Check_Surface_Water.Value = False
Check_Ground_Water.Value = False
Check_Sediment.Value = False
Else
Check_Soil.Enabled = True
End If
End Sub
Private Sub Check_Surface_Water_Click()
'--- Checks if the Surface Water Button is Clicked ---
If Check_Surface_Water.Value = True Then
Check_Soil.Value = False
Check_Ground_Water.Value = False
Check_Sediment.Value = False
Else
Check_Surface_Water.Enabled = True
End If
End Sub
Private Sub Check_Ground_Water_Click()
'--- Checks if the Ground Water Button is Clicked ---
If Check_Ground_Water.Value = True Then
Check_Surface_Water.Value = False
Check_Soil.Value = False
Check_Sediment.Value = False
Else
Check_Ground_Water.Enabled = True
End If
End Sub
Private Sub Check_Sediment_Click()
'--- Checks if the Sediment Button is Clicked ---
If Check_Sediment.Value = True Then
Check_Surface_Water.Value = False
Check_Soil.Value = False
Check_Ground_Water.Value = False
Else
Check_Sediment.Enabled = True
End If
End Sub
我的其他代码:
SubSelect_Correct_Sheet()
' Select_Correct_Sheet Macro
Sheets("Metals").Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = "&""Arial,Bold""Summary of Metals in "
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
End Sub
答案 0 :(得分:1)
尝试这两项更改
1-将你的OK_Click改为:
Private Sub OK_Click()
Dim headerText As String
Select Case True
Case Check_Soil.value: headerText = "Soil"
Case Check_Sediment.value: headerText = "Sediment"
Case Check_Ground_Water.value: headerText = "Ground Water"
Case Check_Surface_Water.value: headerText = "Surface Water"
End Select
headerText = headerText & ", " & TextBox1.value ' <-- assuming this is the name of your textbox
FormatHeader headerText ' <-- now invoke the header formatting sub with parameter
MsgBox "Completed"
End Sub
2-更改标题格式化的例程(旧名称为Select_Correct_Sheet
我为其指定了新名称FormatHeader
)。我的声明中应该有一个参数text
,只有一行会改变,分配文本的那一行是为了添加提供的参数。
Sub FormatHeader(text As String)
' ....
.LeftHeader = "&""Arial,Bold""Summary of Metals in " & text '<-- add the text parameter into header here
' ....
End Sub