PC Review


Reply
Thread Tools Rate Thread

CommandButton to Exit a Macro?

 
 
badger.matthew@gmail.com
Guest
Posts: n/a
 
      23rd Jan 2007
Hi All,

I'm in the process of making the monumentus shift from Excel 97(!) to
2007 and have just discovered the joys of modeless userforms.

I am forever writing macros to edit over 2500 .csv files and have used
the status bar before now to show progress. Now, however, I have
created a modeless userform that gives a visual indication of progress,
using the code below. Is it possible to add a 'Cancel' button somewhere
on UserForm1 to exit the macro on click?

This is what I have:

>>Sub ProgBar()


>>Dim lngInt As Long
>>Dim lngMax As Long



>>lngMax = InputBox("What is lngMax?")


>>With UserForm1


>>.CommandButton1.Caption = "0% Complete"
>>.Show vbModeless


>>For lngInt = 1 To lngMax
>> .Label1.Width = 234 * (lngInt / lngMax)
>> .CommandButton1.Caption = CInt(lngInt * 100 / lngMax) & "% Complete"
>> .Repaint
>>Next lngInt


>>.Hide
>>.CommandButton1.Caption = "Click Run Macro"
>>.Label1.Width = 0


>>End With


>>End Sub


Thanks in advance, Matt

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      23rd Jan 2007
The flickering is a bit annoying, no?

A better example can be found at
http://www.enhanceddatasystems.com/E...rogressBar.htm

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi All,
>
> I'm in the process of making the monumentus shift from Excel 97(!) to
> 2007 and have just discovered the joys of modeless userforms.
>
> I am forever writing macros to edit over 2500 .csv files and have used
> the status bar before now to show progress. Now, however, I have
> created a modeless userform that gives a visual indication of progress,
> using the code below. Is it possible to add a 'Cancel' button somewhere
> on UserForm1 to exit the macro on click?
>
> This is what I have:
>
>>>Sub ProgBar()

>
>>>Dim lngInt As Long
>>>Dim lngMax As Long

>
>
>>>lngMax = InputBox("What is lngMax?")

>
>>>With UserForm1

>
>>>.CommandButton1.Caption = "0% Complete"
>>>.Show vbModeless

>
>>>For lngInt = 1 To lngMax
>>> .Label1.Width = 234 * (lngInt / lngMax)
>>> .CommandButton1.Caption = CInt(lngInt * 100 / lngMax) & "% Complete"
>>> .Repaint
>>>Next lngInt

>
>>>.Hide
>>>.CommandButton1.Caption = "Click Run Macro"
>>>.Label1.Width = 0

>
>>>End With

>
>>>End Sub

>
> Thanks in advance, Matt
>



 
Reply With Quote
 
badger.matthew@gmail.com
Guest
Posts: n/a
 
      23rd Jan 2007
Cheers Bob, works perfectly. Doesn't flicker at all on mine either.

Bob Phillips wrote:
> The flickering is a bit annoying, no?
>
> A better example can be found at
> http://www.enhanceddatasystems.com/E...rogressBar.htm
>
> --
> ---
> HTH
>
> Bob
>
> (change the xxxx to gmail if mailing direct)
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi All,
> >
> > I'm in the process of making the monumentus shift from Excel 97(!) to
> > 2007 and have just discovered the joys of modeless userforms.
> >
> > I am forever writing macros to edit over 2500 .csv files and have used
> > the status bar before now to show progress. Now, however, I have
> > created a modeless userform that gives a visual indication of progress,
> > using the code below. Is it possible to add a 'Cancel' button somewhere
> > on UserForm1 to exit the macro on click?
> >
> > This is what I have:
> >
> >>>Sub ProgBar()

> >
> >>>Dim lngInt As Long
> >>>Dim lngMax As Long

> >
> >
> >>>lngMax = InputBox("What is lngMax?")

> >
> >>>With UserForm1

> >
> >>>.CommandButton1.Caption = "0% Complete"
> >>>.Show vbModeless

> >
> >>>For lngInt = 1 To lngMax
> >>> .Label1.Width = 234 * (lngInt / lngMax)
> >>> .CommandButton1.Caption = CInt(lngInt * 100 / lngMax) & "% Complete"
> >>> .Repaint
> >>>Next lngInt

> >
> >>>.Hide
> >>>.CommandButton1.Caption = "Click Run Macro"
> >>>.Label1.Width = 0

> >
> >>>End With

> >
> >>>End Sub

> >
> > Thanks in advance, Matt
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
CommandButton still visible until enter and then exit design mode =?Utf-8?B?cm9iczMxMzE=?= Microsoft Excel Programming 0 6th Aug 2007 07:48 PM
Unexpected CommandButton Caption Display on Exit =?Utf-8?B?bWlja2V5?= Microsoft Excel Programming 1 28th Dec 2006 11:02 AM
how do i make a commandbutton run a macro?? =?Utf-8?B?U2hheA==?= Microsoft Excel New Users 7 7th Jun 2006 05:16 PM
Commandbutton in UserForm to run Macro salihyil Microsoft Excel Programming 2 16th Feb 2004 05:36 PM
Macro won't run from CommandButton Nathan Gutman Microsoft Excel Programming 3 24th Dec 2003 07:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:05 PM.