/ /ユーザーフォームの結果を見出しに挿入します-Excel、VBA、フォーマット、ユーザーフォーム

見出しにユーザーフォームの結果を挿入する - Excel、VBA、書式設定、ユーザーフォーム

ユーザーフォームの結果をヘッダーに挿入する必要がありますが、コードを組み合わせて最終的なプロジェクトにする方法がわかりません。 以下の写真とコード

ヘッダーの[OK]ボタンが必要です 1:必要なシート(この場合はmetalsと呼ばれるシート)に応じて、ヘッダーコードに従ってヘッダーをフォーマットします

2。 「 "_____"の金属の概要<-(チェックされているボックスに応じて土壌/堆積物...など)」と表示された後

3。入力したテキストをユーザーフォームのテキストボックスに挿入します。 (コードはまだ書かれていません)。

最終結果。 =この特定のシートの場合、「Summary of Metals in Soil、100 Main Street、USA」というヘッダーになります。

すべての助けに感謝します!

以下のコードは、結果を一時的に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

私の他のコード:

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

ここに画像の説明を入力

ここに画像の説明を入力

回答:

回答№1は0

これらの2つの変更を試してください

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 宣言では、1行だけが変更されます。これは、指定されたパラメーターを追加するためにテキストが割り当てられている行です。

Sub FormatHeader(text As String)
" ....
.LeftHeader = "&""Arial,Bold""Summary of Metals in " & text "<-- add the text parameter into header here
" ....
End Sub