Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word 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 July 28th, 2011, 03:53 PM
Authorized User
 
Join Date: May 2011
Posts: 44
Thanks: 7
Thanked 0 Times in 0 Posts
Exclamation adding buttons using loop

Hi,

I am using loops to add my buttons but I do not know how to link the button to a sub that is already there. I have forgotten to take my code with me so this code might not be right but it is along the right lines.

Code:
For intButton = 2 to intButton = 93

     myButton = add.controls(Forms.Button.1, "btnClear" & intButton)
     With myButton
          .left = 616
          .etc
     End with

Next intButton
I did find a bit for code selection.onAction or .onClick(assignMacro) but this wouldn't work in the with. There was also another post about classes but I do not know much about them and am not sure if I have time to learn them.

I also tried making subs with each of the names but that did not work.

Could you please help?

Thanks
 
Old July 29th, 2011, 05:24 AM
Authorized User
 
Join Date: May 2011
Posts: 44
Thanks: 7
Thanked 0 Times in 0 Posts
Talking solved:

I have just solved it. Instead of having many buttons I had the one and moved it when the scroll exceeds a certain position.

Here is the code if anybody wants it:

Code:
Private Sub UserForm_Scroll(ByVal ActionX As MSForms.fmScrollAction, ByVal ActionY As MSForms.fmScrollAction, ByVal RequestDx As Single, ByVal RequestDy As Single, ByVal ActualDx As MSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle)
    
    'Move the button down when the scroll exceeds a certain position
        
    If Me.ScrollTop > intScrollPosition Then
        Me.btnClear.Top = Me.btnClear.Top + 550
        intScrollPosition = intScrollPosition + 550
        intScrollPosition2 = intScrollPosition2 + 550
        
        Else
            'Move the button up when the scroll exceeds a certain position
            
            If Me.ScrollTop < intScrollPosition2 Then
                Me.btnClear.Top = Me.btnClear.Top - 550
                intScrollPosition2 = intScrollPosition2 - 550
                intScrollPosition = intScrollPosition - 550
            End If
    End If

    
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
Adding similiar occurences with loop musman0047 XSLT 7 February 18th, 2009 12:18 AM
Dynamic Buttons,SaveToolStrip, adding records KeviJay VB Databases Basics 2 May 28th, 2008 12:46 PM
Adding Properties to Buttons in a GridView Aaron Edwards ASP.NET 2.0 Basics 3 July 23rd, 2006 01:48 PM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





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