3
我需要所有的L欄一個文本框內複製我的工作表Sheet1 的對Sheet4。
我嘗試用這個來做:整列複製到一個文本框
Sub ToTB()
Sheets("Sheet4").TextBoxes("TextBox 2").Text = Sheets("Sheet1").Range("L:L").Text
End Sub
但隨後出現此消息:
應用程序定義或對象定義的錯誤
任何建議?
我需要所有的L欄一個文本框內複製我的工作表Sheet1 的對Sheet4。
我嘗試用這個來做:整列複製到一個文本框
Sub ToTB()
Sheets("Sheet4").TextBoxes("TextBox 2").Text = Sheets("Sheet1").Range("L:L").Text
End Sub
但隨後出現此消息:
應用程序定義或對象定義的錯誤
任何建議?
這裏有點直接。如果你已經有了文本框,只是需要從距離單元的添加值:
Sub Test()
Dim srng As Range
Dim sWs As Worksheet: Set sWs = Sheets("Sheet1")
Set srng = sWs.Range("L1", sWs.Range("L" & sWs.Rows.Count).End(xlUp))
With Sheets("Sheet4").Shapes("Textbox 2").OLEFormat.Object
.Text = Join(Application.Transpose(srng), vbCrLf)
End With
End Sub
,或者如果你希望它添加什麼加里發佈:
Sub Test()
Dim sWs As Worksheet, dWs As Worksheet
Set sWs = Sheets("Sheet1"): Set dWs = Sheets("Sheet4")
Dim dRng As Range, sRng As Range
Set dRng = dWs.Range("A1:A10") 'change to suit
Set sRng = sWs.Range("L1", sWs.Range("L" & sWs.Rows.Count).End(xlUp))
With dWs.Shapes.AddTextbox(msoTextOrientationHorizontal, _
dRng.Left, dRng.Top, dRng.Width, dRng.Height).OLEFormat.Object
.Text = Join(Application.Transpose(sRng), vbCrLf)
End With
End Sub
有了這個Sheet4:
運行此宏:
Sub CoverRange()
msg = ""
Sheets("Sheet4").Activate
For Each r In Intersect(ActiveSheet.UsedRange, Range("L:L"))
msg = msg & vbCrLf & r.Text
Next r
Sheets("Sheet1").Activate
Dim L As Long, T As Long, W As Long, H As Long
Set r = Range("B9:B20")
L = r.Left
T = r.Top
W = r.Width
H = r.Height
With ActiveSheet.Shapes
.AddTextbox(msoTextOrientationHorizontal, L, T, W, H).Select
End With
Selection.Characters.Text = msg
End Sub
將在工作表Sheet1
產生這種210
非常感謝Gary的,這正是我正在尋找 – 2015-03-13 22:32:34
@JorgeMolano檢查[接受答案](http://stackoverflow.com/help/someone-answers)作爲在Stackoverflow中說'Thank you'的一種方式。它也很好地解釋了[這裏](http://stackoverflow.com/tour)。 – L42 2015-03-13 23:53:33