我試圖創建一個Excel函數,該函數將以我請求的任何形式將它告訴它的任何範圍加粗。不幸的是,我只是在正確傳遞變量並獲得這個結果方面取得了部分成功。當然,沒有人喜歡一個部分,所以有人可以讓我知道我錯過了什麼。Excel VBA - 將參數傳遞給某個函數
Sub Macro1()
On Error Resume Next
'Create & reset testing area.
Range("A1:C6").value = "A"
Range("A1:C6").Font.Bold = False
[b2].Select
'The two lines below call the function perfectly and the cells are bolded without issue
Text_bold ([a1])
Text_bold (Cells(2, 1))
'However, the party stops there as the following code errors out.
Text_bold ([b1].Address)
Text_bold (Selection)
Text_bold (Range("B3"))
'Similarly, the below fails as well...
Text_bold (Range("B4:C4"))
'And even less surprising, the following also refuses to assist in the endeavor...
Text_bold (Application.Union(Range("B5:C5"), Range("B6:C6")))
End Sub
Function Text_bold(x As Range)
'MsgBox VarType(x)
x.Font.Bold = True
End Function
請幫忙。
更多的瞭解,我認爲這是有幫助的注意,那些失敗的行失敗,因爲Range對象提供Range.Value而不是作爲對象本身 – serakfalcon
@serafalcon傳遞,是指出。謝謝。 –
另外,如果您嘗試使用不帶調用的圓括號調用多參數函數,則會出現語法錯誤,如:FunctionX(param1,param2) –