Sizing problem with adding buttons

RiaM

Board Regular
Joined
Jun 5, 2009
Messages
67
Hi guys, I've written a macro to add buttons to a sheet of mine. The buttons call up various other macros. The problem I'm having seems to be a screen update. I've set the button size to be greater than the number of characters it contains. However when I run the macro, it first adds the button at its default size (width which is too small), and bombs out. Any ideas how to get away from this? Below is the code I'm using:

Dim Width As Integer, Height As Integer, HzSpace As Integer, VtPos as integer

'Dimensions
Width = 144
Height = 20
VtPos = 400
HzPos = 275

ActiveSheet.Buttons.Add(HzPos, VtPos, Width, Height).Select
Selection.OnAction = "AdvertiserByIssueDateWeekday"
Selection.ShapeRange.ScaleWidth 1, msoFalse, msoScaleFromTopLeft
Selection.HorizontalAlignment = xlLeft
Selection.Characters.Text = " Advertiser by IssueDate: Weekday"
With Selection.Characters(Start:=1, Length:=40).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
End With

Thanks,
Ria
 
This version of your original code works fine for me:
Code:
Dim Width As Integer, Height As Integer, HzPos As Integer, VtPos As Integer
'Dimensions
Width = 144
Height = 20
VtPos = 400
HzPos = 275
With ActiveSheet.Buttons.Add(HzPos, VtPos, Width, Height)
   .OnAction = "AdvertiserByIssueDateWeekday"
   .ShapeRange.ScaleWidth 1, msoFalse, msoScaleFromTopLeft
   .HorizontalAlignment = xlLeft
   .Characters.Text = " Advertiser by IssueDate: Weekday"
   With .Characters(Start:=1, Length:=40).Font
      .Name = "Calibri"
      .FontStyle = "Regular"
      .Size = 11
   End With
End With
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I read on other site that this might be a limitation with form controls in Excel 2007 and that one should try using ActiveX Controls

Any idea how to do this? I'm so lost
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top