Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2008, 04:11 AM
Registered User
 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel VB : How to change Label Caption

I have one button and 10 labels stacked in a column in my worksheet.
Now when I press the button each time, it clears the caption of the last label from the bottom of the stack that has some caption displayed.
My work sheet looks as below.

Label caption 1
Label caption 2
Label caption 3
Label caption 4
Label caption 5
Label blank
Label blank
Label blank


5 <- this cell below the above label stack holds cell pointing at the last Label having Caption "Label caption 5"

[Button]<- Pressing this button each time would change a Label's caption from "Label Caption #" to "Label blank".

Can any one help me with this?

pap
 
Old September 22nd, 2008, 04:46 PM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

This an exercise for you? Why not just have 1 label and rename the caption each time based on previous name? How are you tracking the label number it is on? How would the labels reset?
Assuming they're named Caption_Labelx where X is 1 thru 10 and it's unknown which level is currently blank then the code should be something like this:
----------------------------------------------------
  Dim iCount As Integer, oSheet As Worksheet
  Set oSheet = ActiveWorkbook.ActiveSheet
  Do While iCount < 10 And oSheet.OLEObjects("Caption_Label" & 10 - iCount).Object.Caption = "Label blank"
    iCount = iCount + 1
  Loop
  If iCount < 10 _
    Then oSheet.OLEObjects("Caption_Label" & 10 - iCount).Object.Caption = "Label blank" _
    Else MsgBox "All Label captions set to 'Label blank'", , "Notification"
----------------------------------------------------






Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Caption HtmlInputFile but it doest not upl. Israr HTML Code Clinic 1 April 25th, 2008 04:08 AM
Change button caption on continuous subform PeregrinTook Access VBA 2 April 16th, 2007 05:16 PM
CAPTION OF ACCESS DB IN VB akash VB How-To 5 March 8th, 2007 11:01 PM
Change Caption HtmlInputFile Israr ASP.NET 1.0 and 1.1 Professional 4 November 8th, 2006 02:32 AM
saving changes to label caption Loralee Access 5 January 6th, 2006 09:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.