ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   TextBox refusal (https://www.excelbanter.com/excel-programming/278966-textbox-refusal.html)

Garry Jones

TextBox refusal
 
I have been trying to change the width of a textbox on a user form with
code, but it keeps on going back to it's original size that I set in
design.

How can I let a user alter the size of a text box with a number

I know how to get a number from the user, and check that number.

Say I get 80 from the user the width is currently 40

Then my code looks like this.. (after controls and reading of variables.

UserForm1.Controls(TextBox1.width) = 80

I have also tried

TextBox1.width = 80

But something is missing here.

Because when I close whatever code I write the text boxes go back to the
original place and size in the formula.

I have put these commands behind command buttons and in UserForm
Initialise. Still doens't work.

Any ideas/links?

Garry Jones
Sweden

Harald Staff[_6_]

TextBox refusal
 
Man, you're like a Do-While loop <bg. "You have to save the settings somewhere and read
them back on next load. "

Drumroll, Demo:
Create a userform with Textbox1 and Commandbutton1 in a new workbook with at least 3
worksheets. Userform code:

Private Sub UserForm_Initialize()
If Sheets(3).Cells(1, 1).Value 5 Then
TextBox1.Width = Sheets(3).Cells(1, 1).Value
End If
End Sub

Private Sub CommandButton1_Click()
Dim W As Long
On Error Resume Next
W = Val(InputBox("How wide ?", "Textbox1 width", TextBox1.Width))
If W 5 Then
Sheets(3).Cells(1, 1).Value = W
TextBox1.Width = W
End If
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Garry Jones" wrote in message ...
I have been trying to change the width of a textbox on a user form with
code, but it keeps on going back to it's original size that I set in
design.

How can I let a user alter the size of a text box with a number

I know how to get a number from the user, and check that number.

Say I get 80 from the user the width is currently 40

Then my code looks like this.. (after controls and reading of variables.

UserForm1.Controls(TextBox1.width) = 80

I have also tried

TextBox1.width = 80

But something is missing here.

Because when I close whatever code I write the text boxes go back to the
original place and size in the formula.

I have put these commands behind command buttons and in UserForm
Initialise. Still doens't work.

Any ideas/links?

Garry Jones
Sweden




merjet

TextBox refusal
 
Not sure I grasp your problem. However, if you want
to allow the user to set the width of a TextBox and the
TextBox to have that same width the next time the
UserForm loads, it seems to me you will need to use a
worksheet cell to set the width. When the UserForm
loads, set the TextBox width per this cell with code.
Also, if the user changes the width, send the result to
the same cell.

HTH,
Merjet



Garry Jones

TextBox refusal
 
Harald Staff wrote:

Man, you're like a Do-While loop <bg. "You have to save the settings somewhere and read
them back on next load. "


The penny - buck - krona finally dropped....

I was trying to do something that was not possible.

I have a user form. I wanted to move the physical place of the text
boxes on the user form that I see in the design layout. These values are
probably hard coded somewhere but I doubt it's possible to move them.

So I moved them by hand.

Thanks for your help and time you spent on this.

Garry Jones


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com