2017-02-12 67 views
0

我需要我的用戶窗體的結果插入到一個頭,但我不知道怎麼我的代碼結合成一個最終項目:照片和下面的代碼插入結果放入標題

我需要頭OK按鈕 :格式化的頭按取決於我想要什麼表我的頭碼,在這種情況下,片稱爲金屬

。之後它說_____‘<「在金屬的總結。’ - (土壤/沉積物...等等,這取決於檢查框)

插入文本有史以來輸入什麼到窗體的文本框(無。編寫的代碼還)。

最終的結果。 =對於這個特殊的表將是頭說:「土壤中金屬的總結,100大街,美國」

所有幫助表示讚賞!

下面的代碼插入到結果A1只是臨時 私人小組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 

我的其他CODE:

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 

enter image description here

enter image description here

回答

0

嘗試這兩個變化

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 
+0

....謝謝!你的解決方案是完美的,比我寫的更有說服力。我要向你扔一個曲線球......如果我有多個不同名稱的圖紙,可以說sheet1,sheet2,sheet 3.是否有添加代碼的方法。 Sheet1在土壤中的總結「然後下一張是」Sheet2在土壤中的總結「......等等......我無法強調我多麼感謝你的幫助! –

+0

這將是在' OK_Click':'headerText =「&ActiveSheet.name的概要&」in&headerText&「,」&TextBox1.value'「。然後在'Sub FormatHeader':'.LeftHeader =「&」「Arial,Bold」「」&text'。 –

+0

你的回答是奇妙的 –