OK Graham, the code below makes a sample workbook with VBA code.
Place this code in the standard module and run, then a sample worksheet will
be made.
Please have a look at code and objects names.
Hope this helps.
Sub MakeSampleWbk()
Dim wbSample As Workbook
Dim lngShINW As Long
Dim arrNames As Variant
Dim strCode As String
Dim i As Long
arrNames = Array("a", "b", "c", "d")
lngShINW = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 4
Set wbSample = Workbooks.Add '//Add Worksheet
Application.SheetsInNewWorkbook = lngShINW
For i = 1 To 4 '//Add Objects and Make code for CommandButton
With wbSample
With
..Sheets(i).OLEObjects.Add(ClassType:="Forms.OptionButton.1", _
Left:=50, Top:=50, Width:=100,
Height:=20)
.Name = arrNames(i - 1)
.Object.Caption = "This name is " & arrNames(i - 1)
End With
.Sheets(1).OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Left:=150, Top:=15 + 30 * i,
Width:=120, Height:=30).Name _
= "CommandButton" & i
strCode = strCode & _
"Private Sub CommandButton" & i & "_Click()" & vbLf &
vbTab & _
"Sheet" & i & "." & "Select" & vbLf & vbTab & _
"Sheet" & i & "." & arrNames(i - 1) & ".Value = True"
& vbLf & _
"End Sub" & vbLf & vbLf
End With
Next
With wbSample.VBProject.VBComponents.Item("Sheet1").CodeModule
.DeleteLines 1, .CountOfLines '//Delete Codes already
wrriten
.InsertLines 1, strCode '// Write Code
End With
End Sub
--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters'
URL:
http://www.interq.or.jp/sun/puremis/colo/CellMastersLink.htm
mailto:
[email protected]
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
GrahamD said:
Thanks for the quick reply Colo.
However, I keep getting a "compile error",
"Method or data member not found", with the (.a) in the code
highlighted?
Confused...
------------------------------------------------
~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements