Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Embedding Objects

Hi

I am trying to embed buttons and labels on my spreadsheet in code.

The code I am using is as follows

Dim btn As OLEObject
Dim Label1 As OLEObject

lngLeft = 138
lngTop = 63.75
n = 1
Do Until grstFutureOrdersMaster.EOF
dteStore = grstFutureOrdersMaster("Production_Date")
Set btn =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Left:=lngLeft, Top:=lngTop, Width:=116.25, Height:=33)
btn.Name = "cmdWO" & n
btn.Object.WordWrap = True
btn.Object.Caption = grstFutureOrdersMaster("ITEM_NUMBER") & vbCr &
grstFutureOrdersMaster("ACCOUNT_NUMBER")
If lngLeft = 138 Then
Set Label1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label .1", _
Left:=63.75, Top:=lngTop + 6, Width:=71.25, Height:=20.25)
Label1.Name = "Label" & n
Label1.Object.Caption = grstFutureOrdersMaster("Production_Date")
Label1.Object.Font.Size = 12
End If

Select Case grstFutureOrdersMaster("LINE")
Case "LINE1"
btn.Object.BackColor = &H8080FF
Case "LINE2"
btn.Object.BackColor = &H80FFFF
Case "LINE3"
btn.Object.BackColor = &HC0FFC0
Case Else
btn.Object.BackColor = &HFFC0C0
End Select
Worksheets(2).Range("A" & n & ":A" & n) =
grstFutureOrdersMaster("ITEM_NUMBER")
Worksheets(2).Range("B" & n & ":B" & n) =
grstFutureOrdersMaster("ITEM_DESCRIPTION_1")
Worksheets(2).Range("C" & n & ":C" & n) =
grstFutureOrdersMaster("REFERENCE")
Worksheets(2).Range("D" & n & ":D" & n) =
grstFutureOrdersMaster("ACCOUNT_NUMBER")
Worksheets(2).Range("E" & n & ":E" & n) =
grstFutureOrdersMaster("ACCOUNT_NAME")
Worksheets(2).Range("F" & n & ":F" & n) =
grstFutureOrdersMaster("LINE")
Worksheets(2).Range("G" & n & ":G" & n) =
grstFutureOrdersMaster("Production_Date")
grstFutureOrdersMaster.MoveNext
If Not grstFutureOrdersMaster.EOF Then
If grstFutureOrdersMaster("Production_Date") = dteStore Then
lngLeft = lngLeft + 117
Else
dteStore = grstFutureOrdersMaster("Production_Date")
lngLeft = 138
lngTop = lngTop + 33
End If
End If
n = n + 1
Loop

The buttons are all appearing OK but their names seem somewhat random. They
should all be cmdWO1; cmdWO2; cmdWO3, etc, but sometimes this is working and
sometimes they are being named just as CommandButton25 or similar.

I need to be able to name them so that I can then insert the relevant code
programmatically that relates to the button. The determining factor is
obviously the number of records in my recordset (which will vary from run to
run). This can be several hundred.

The other thing that is odd is that Excel places all the buttons on the
sheet and THEN goes through them and adds the text, backcolor, etc.

What am I doing wrong?
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Embedding Objects

You aren't trying to use names already used by any chance?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"RoyT" wrote in message
...
Hi

I am trying to embed buttons and labels on my spreadsheet in code.

The code I am using is as follows

Dim btn As OLEObject
Dim Label1 As OLEObject

lngLeft = 138
lngTop = 63.75
n = 1
Do Until grstFutureOrdersMaster.EOF
dteStore = grstFutureOrdersMaster("Production_Date")
Set btn =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Left:=lngLeft, Top:=lngTop, Width:=116.25, Height:=33)
btn.Name = "cmdWO" & n
btn.Object.WordWrap = True
btn.Object.Caption = grstFutureOrdersMaster("ITEM_NUMBER") & vbCr &
grstFutureOrdersMaster("ACCOUNT_NUMBER")
If lngLeft = 138 Then
Set Label1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label .1", _
Left:=63.75, Top:=lngTop + 6, Width:=71.25, Height:=20.25)
Label1.Name = "Label" & n
Label1.Object.Caption =
grstFutureOrdersMaster("Production_Date")
Label1.Object.Font.Size = 12
End If

Select Case grstFutureOrdersMaster("LINE")
Case "LINE1"
btn.Object.BackColor = &H8080FF
Case "LINE2"
btn.Object.BackColor = &H80FFFF
Case "LINE3"
btn.Object.BackColor = &HC0FFC0
Case Else
btn.Object.BackColor = &HFFC0C0
End Select
Worksheets(2).Range("A" & n & ":A" & n) =
grstFutureOrdersMaster("ITEM_NUMBER")
Worksheets(2).Range("B" & n & ":B" & n) =
grstFutureOrdersMaster("ITEM_DESCRIPTION_1")
Worksheets(2).Range("C" & n & ":C" & n) =
grstFutureOrdersMaster("REFERENCE")
Worksheets(2).Range("D" & n & ":D" & n) =
grstFutureOrdersMaster("ACCOUNT_NUMBER")
Worksheets(2).Range("E" & n & ":E" & n) =
grstFutureOrdersMaster("ACCOUNT_NAME")
Worksheets(2).Range("F" & n & ":F" & n) =
grstFutureOrdersMaster("LINE")
Worksheets(2).Range("G" & n & ":G" & n) =
grstFutureOrdersMaster("Production_Date")
grstFutureOrdersMaster.MoveNext
If Not grstFutureOrdersMaster.EOF Then
If grstFutureOrdersMaster("Production_Date") = dteStore Then
lngLeft = lngLeft + 117
Else
dteStore = grstFutureOrdersMaster("Production_Date")
lngLeft = 138
lngTop = lngTop + 33
End If
End If
n = n + 1
Loop

The buttons are all appearing OK but their names seem somewhat random.
They
should all be cmdWO1; cmdWO2; cmdWO3, etc, but sometimes this is working
and
sometimes they are being named just as CommandButton25 or similar.

I need to be able to name them so that I can then insert the relevant code
programmatically that relates to the button. The determining factor is
obviously the number of records in my recordset (which will vary from run
to
run). This can be several hundred.

The other thing that is odd is that Excel places all the buttons on the
sheet and THEN goes through them and adds the text, backcolor, etc.

What am I doing wrong?
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Embedding Objects

Funny you should say that

Further experimentation has shown that it all works fine the first time it
is run but if I run it again that is when I get the problems.

Even thought I remove all the buttons before I repopulate the sheet

Do you think that Excel is storing the names somewhere and I need to somehow
clear this? How?

Roy
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)


"Bob Phillips" wrote:

You aren't trying to use names already used by any chance?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"RoyT" wrote in message
...
Hi

I am trying to embed buttons and labels on my spreadsheet in code.

The code I am using is as follows

Dim btn As OLEObject
Dim Label1 As OLEObject

lngLeft = 138
lngTop = 63.75
n = 1
Do Until grstFutureOrdersMaster.EOF
dteStore = grstFutureOrdersMaster("Production_Date")
Set btn =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Left:=lngLeft, Top:=lngTop, Width:=116.25, Height:=33)
btn.Name = "cmdWO" & n
btn.Object.WordWrap = True
btn.Object.Caption = grstFutureOrdersMaster("ITEM_NUMBER") & vbCr &
grstFutureOrdersMaster("ACCOUNT_NUMBER")
If lngLeft = 138 Then
Set Label1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label .1", _
Left:=63.75, Top:=lngTop + 6, Width:=71.25, Height:=20.25)
Label1.Name = "Label" & n
Label1.Object.Caption =
grstFutureOrdersMaster("Production_Date")
Label1.Object.Font.Size = 12
End If

Select Case grstFutureOrdersMaster("LINE")
Case "LINE1"
btn.Object.BackColor = &H8080FF
Case "LINE2"
btn.Object.BackColor = &H80FFFF
Case "LINE3"
btn.Object.BackColor = &HC0FFC0
Case Else
btn.Object.BackColor = &HFFC0C0
End Select
Worksheets(2).Range("A" & n & ":A" & n) =
grstFutureOrdersMaster("ITEM_NUMBER")
Worksheets(2).Range("B" & n & ":B" & n) =
grstFutureOrdersMaster("ITEM_DESCRIPTION_1")
Worksheets(2).Range("C" & n & ":C" & n) =
grstFutureOrdersMaster("REFERENCE")
Worksheets(2).Range("D" & n & ":D" & n) =
grstFutureOrdersMaster("ACCOUNT_NUMBER")
Worksheets(2).Range("E" & n & ":E" & n) =
grstFutureOrdersMaster("ACCOUNT_NAME")
Worksheets(2).Range("F" & n & ":F" & n) =
grstFutureOrdersMaster("LINE")
Worksheets(2).Range("G" & n & ":G" & n) =
grstFutureOrdersMaster("Production_Date")
grstFutureOrdersMaster.MoveNext
If Not grstFutureOrdersMaster.EOF Then
If grstFutureOrdersMaster("Production_Date") = dteStore Then
lngLeft = lngLeft + 117
Else
dteStore = grstFutureOrdersMaster("Production_Date")
lngLeft = 138
lngTop = lngTop + 33
End If
End If
n = n + 1
Loop

The buttons are all appearing OK but their names seem somewhat random.
They
should all be cmdWO1; cmdWO2; cmdWO3, etc, but sometimes this is working
and
sometimes they are being named just as CommandButton25 or similar.

I need to be able to name them so that I can then insert the relevant code
programmatically that relates to the button. The determining factor is
obviously the number of records in my recordset (which will vary from run
to
run). This can be several hundred.

The other thing that is odd is that Excel places all the buttons on the
sheet and THEN goes through them and adds the text, backcolor, etc.

What am I doing wrong?
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Embedding Objects

No I wouldn't think it is that, but are you sure that you are removing them
ALL?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"RoyT" wrote in message
...
Funny you should say that

Further experimentation has shown that it all works fine the first time it
is run but if I run it again that is when I get the problems.

Even thought I remove all the buttons before I repopulate the sheet

Do you think that Excel is storing the names somewhere and I need to
somehow
clear this? How?

Roy
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)


"Bob Phillips" wrote:

You aren't trying to use names already used by any chance?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"RoyT" wrote in message
...
Hi

I am trying to embed buttons and labels on my spreadsheet in code.

The code I am using is as follows

Dim btn As OLEObject
Dim Label1 As OLEObject

lngLeft = 138
lngTop = 63.75
n = 1
Do Until grstFutureOrdersMaster.EOF
dteStore = grstFutureOrdersMaster("Production_Date")
Set btn =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Left:=lngLeft, Top:=lngTop, Width:=116.25, Height:=33)
btn.Name = "cmdWO" & n
btn.Object.WordWrap = True
btn.Object.Caption = grstFutureOrdersMaster("ITEM_NUMBER") &
vbCr &
grstFutureOrdersMaster("ACCOUNT_NUMBER")
If lngLeft = 138 Then
Set Label1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label .1", _
Left:=63.75, Top:=lngTop + 6, Width:=71.25,
Height:=20.25)
Label1.Name = "Label" & n
Label1.Object.Caption =
grstFutureOrdersMaster("Production_Date")
Label1.Object.Font.Size = 12
End If

Select Case grstFutureOrdersMaster("LINE")
Case "LINE1"
btn.Object.BackColor = &H8080FF
Case "LINE2"
btn.Object.BackColor = &H80FFFF
Case "LINE3"
btn.Object.BackColor = &HC0FFC0
Case Else
btn.Object.BackColor = &HFFC0C0
End Select
Worksheets(2).Range("A" & n & ":A" & n) =
grstFutureOrdersMaster("ITEM_NUMBER")
Worksheets(2).Range("B" & n & ":B" & n) =
grstFutureOrdersMaster("ITEM_DESCRIPTION_1")
Worksheets(2).Range("C" & n & ":C" & n) =
grstFutureOrdersMaster("REFERENCE")
Worksheets(2).Range("D" & n & ":D" & n) =
grstFutureOrdersMaster("ACCOUNT_NUMBER")
Worksheets(2).Range("E" & n & ":E" & n) =
grstFutureOrdersMaster("ACCOUNT_NAME")
Worksheets(2).Range("F" & n & ":F" & n) =
grstFutureOrdersMaster("LINE")
Worksheets(2).Range("G" & n & ":G" & n) =
grstFutureOrdersMaster("Production_Date")
grstFutureOrdersMaster.MoveNext
If Not grstFutureOrdersMaster.EOF Then
If grstFutureOrdersMaster("Production_Date") = dteStore Then
lngLeft = lngLeft + 117
Else
dteStore = grstFutureOrdersMaster("Production_Date")
lngLeft = 138
lngTop = lngTop + 33
End If
End If
n = n + 1
Loop

The buttons are all appearing OK but their names seem somewhat random.
They
should all be cmdWO1; cmdWO2; cmdWO3, etc, but sometimes this is
working
and
sometimes they are being named just as CommandButton25 or similar.

I need to be able to name them so that I can then insert the relevant
code
programmatically that relates to the button. The determining factor is
obviously the number of records in my recordset (which will vary from
run
to
run). This can be several hundred.

The other thing that is odd is that Excel places all the buttons on the
sheet and THEN goes through them and adds the text, backcolor, etc.

What am I doing wrong?
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Embedding Objects

Hi Bob

Thanks for your help

I have now discovered that if I rename the buttons before I remove them from
the sheet it all works fine. Over and Over again.

Just for completeness the code I am using to remove them is as follows:

intCount = Worksheets(1).Shapes.Count
For intCounter = intCount To 1 Step -1
If Worksheets(1).Shapes.Item(intCounter).Name < "go" Then
Worksheets(1).Shapes(intCounter).Name = "cmd" & intCount
Worksheets(1).Shapes(intCounter).Delete
End If
Next intCounter

By adding the line:

Worksheets(1).Shapes(intCounter).Name = "cmd" & intCount

All works fine.

So it looks as if Excel IS remembering the names of the buttons, even though
they have been deleted from the sheet.(!)

Roy
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)


"Bob Phillips" wrote:

No I wouldn't think it is that, but are you sure that you are removing them
ALL?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"RoyT" wrote in message
...
Funny you should say that

Further experimentation has shown that it all works fine the first time it
is run but if I run it again that is when I get the problems.

Even thought I remove all the buttons before I repopulate the sheet

Do you think that Excel is storing the names somewhere and I need to
somehow
clear this? How?

Roy
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)


"Bob Phillips" wrote:

You aren't trying to use names already used by any chance?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"RoyT" wrote in message
...
Hi

I am trying to embed buttons and labels on my spreadsheet in code.

The code I am using is as follows

Dim btn As OLEObject
Dim Label1 As OLEObject

lngLeft = 138
lngTop = 63.75
n = 1
Do Until grstFutureOrdersMaster.EOF
dteStore = grstFutureOrdersMaster("Production_Date")
Set btn =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Left:=lngLeft, Top:=lngTop, Width:=116.25, Height:=33)
btn.Name = "cmdWO" & n
btn.Object.WordWrap = True
btn.Object.Caption = grstFutureOrdersMaster("ITEM_NUMBER") &
vbCr &
grstFutureOrdersMaster("ACCOUNT_NUMBER")
If lngLeft = 138 Then
Set Label1 =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label .1", _
Left:=63.75, Top:=lngTop + 6, Width:=71.25,
Height:=20.25)
Label1.Name = "Label" & n
Label1.Object.Caption =
grstFutureOrdersMaster("Production_Date")
Label1.Object.Font.Size = 12
End If

Select Case grstFutureOrdersMaster("LINE")
Case "LINE1"
btn.Object.BackColor = &H8080FF
Case "LINE2"
btn.Object.BackColor = &H80FFFF
Case "LINE3"
btn.Object.BackColor = &HC0FFC0
Case Else
btn.Object.BackColor = &HFFC0C0
End Select
Worksheets(2).Range("A" & n & ":A" & n) =
grstFutureOrdersMaster("ITEM_NUMBER")
Worksheets(2).Range("B" & n & ":B" & n) =
grstFutureOrdersMaster("ITEM_DESCRIPTION_1")
Worksheets(2).Range("C" & n & ":C" & n) =
grstFutureOrdersMaster("REFERENCE")
Worksheets(2).Range("D" & n & ":D" & n) =
grstFutureOrdersMaster("ACCOUNT_NUMBER")
Worksheets(2).Range("E" & n & ":E" & n) =
grstFutureOrdersMaster("ACCOUNT_NAME")
Worksheets(2).Range("F" & n & ":F" & n) =
grstFutureOrdersMaster("LINE")
Worksheets(2).Range("G" & n & ":G" & n) =
grstFutureOrdersMaster("Production_Date")
grstFutureOrdersMaster.MoveNext
If Not grstFutureOrdersMaster.EOF Then
If grstFutureOrdersMaster("Production_Date") = dteStore Then
lngLeft = lngLeft + 117
Else
dteStore = grstFutureOrdersMaster("Production_Date")
lngLeft = 138
lngTop = lngTop + 33
End If
End If
n = n + 1
Loop

The buttons are all appearing OK but their names seem somewhat random.
They
should all be cmdWO1; cmdWO2; cmdWO3, etc, but sometimes this is
working
and
sometimes they are being named just as CommandButton25 or similar.

I need to be able to name them so that I can then insert the relevant
code
programmatically that relates to the button. The determining factor is
obviously the number of records in my recordset (which will vary from
run
to
run). This can be several hundred.

The other thing that is odd is that Excel places all the buttons on the
sheet and THEN goes through them and adds the text, backcolor, etc.

What am I doing wrong?
--
Roy Thompson
Independent Developer
Specialist in Sage Accounting solutions (UK)






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedding PDF simon Excel Discussion (Misc queries) 0 February 26th 10 04:12 PM
Excel VBA Class Objects - Parent & Successor Objects [email protected] Excel Programming 1 January 15th 07 12:06 AM
Embedding Objects... Steven Sinclair Excel Discussion (Misc queries) 1 October 30th 06 09:18 PM
Dynamically Assign Objects to Form Objects. The Vision Thing Excel Programming 2 December 11th 04 04:02 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian[_7_] Excel Programming 1 August 26th 04 10:49 PM


All times are GMT +1. The time now is 11:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"