Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Button on condition

Hello Experts,
I'm having trouble adding a Button because the macro recorder has preset
the Button name to be Button 1. If I were to delete this button and run
the macro again, the code will try to name the button as Button 1 again
but Excel wants to increment it by 1 digit. What's the work around?

Before this button appears, I'd like to have a msgbox first. Lastly,
what's the code for deleting this button after execution?

'Msgbox Required
'"More changes may be required" --- Line 1
'"Are you ready to Export?" --- Line 2
'Option Yes = Call Export macro
'Option No = Stop any other actions and run this following code only

Application.CommandBars("Forms").Visible = True
ActiveSheet.Buttons.Add(232.5, 8.25, 93.75, 36).Select
Selection.OnAction = "ChangeRevenueTitles"
ActiveSheet.Shapes("Button 1").Select
Selection.Characters.Text = "Export"
With Selection.Characters(Start:=1, Length:=6).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
End With
Range("A5").Select
ActiveWindow.FreezePanes = True
Application.CommandBars("Forms").Visible = False
End Sub


'Within the Call Export code, what's the code for deleting this
button after execution?
'and if no button exists, no error message (something like On Error
Resume Next)

Sincerely, thank-you in advance.

Ricky

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Button on condition

Hi Ricky,

I am not sure that I have understood fully your scenario, but try something
like:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim myButton As Button
Dim res As VbMsgBoxResult
Dim sStr As String

Set SH = ActiveSheet '<<==== CHANGE

sStr = "More changes may be required" & vbNewLine _
& "Are you ready to Export?"

res = MsgBox(Prompt:=sStr, Buttons:=vbYesNo)

If res = vbYes Then
Call Export
End If

Set myButton = SH.Buttons.Add(232.5, 8.25, 93.75, 36)
With myButton
.OnAction = "ChangeRevenueTitles"
.Caption = "Export"
With .Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
End With
End With
End Sub
'<<=============


'=============
Sub ChangeRevenueTitles()
'Your code
ActiveSheet.Buttons(Application.Caller).Delete
End Sub
'<<=============



---
Regards,
Norman


"Ricky Pang" wrote in message
...
Hello Experts,
I'm having trouble adding a Button because the macro recorder has preset
the Button name to be Button 1. If I were to delete this button and run
the macro again, the code will try to name the button as Button 1 again
but Excel wants to increment it by 1 digit. What's the work around?

Before this button appears, I'd like to have a msgbox first. Lastly,
what's the code for deleting this button after execution?

'Msgbox Required
'"More changes may be required" --- Line 1
'"Are you ready to Export?" --- Line 2
'Option Yes = Call Export macro
'Option No = Stop any other actions and run this following code only

Application.CommandBars("Forms").Visible = True
ActiveSheet.Buttons.Add(232.5, 8.25, 93.75, 36).Select
Selection.OnAction = "ChangeRevenueTitles"
ActiveSheet.Shapes("Button 1").Select
Selection.Characters.Text = "Export"
With Selection.Characters(Start:=1, Length:=6).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
End With
Range("A5").Select
ActiveWindow.FreezePanes = True
Application.CommandBars("Forms").Visible = False
End Sub


'Within the Call Export code, what's the code for deleting this
button after execution?
'and if no button exists, no error message (something like On Error
Resume Next)

Sincerely, thank-you in advance.

Ricky

*** Sent via Developersdex http://www.developersdex.com ***



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
lookup with multiple condition, but one condition to satisfy is en Eddy Stan Excel Worksheet Functions 2 October 27th 07 02:06 PM
Deactivating a Forms macro button based on a worksheet condition? Ace70 Excel Discussion (Misc queries) 3 June 10th 07 10:31 PM
How do I hide a command button based on a condition? [email protected] Excel Programming 4 May 3rd 06 02:47 PM
Set condition of button on click Robb Quirk Excel Programming 2 February 14th 06 07:18 PM
activate/deactivate button with macro at given condition arcq Excel Programming 1 March 17th 05 05:35 AM


All times are GMT +1. The time now is 12:32 AM.

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

About Us

"It's about Microsoft Excel"