SantanaKRE8s
Board Regular
- Joined
- Jul 11, 2023
- Messages
- 131
- Office Version
- 365
- Platform
- Windows
Can someone check this code please, to see why its not starting at the center of my sheet. I copied it from another workbook and made the changes to names but still not starting in the center.
Sub UserForm()
Dim i As Integer
'Typical approach for zero based collection is to use For i = 0 To [collection].Count-1
'If there is only 1 form open that counter will become For i = 0 to 0 (because of 1-1)
'This approach makes the counter from 1 to 1 when only 1 form is open
'and Userforms(i-1) produces the correct zero based starting point for the collection
'If count = 0 then no form is open, skip to With block, else test if open form name is UserForm.
'If true, close it and exit sub
For i = 1 To VBA.UserForms.Count
If VBA.UserForms(i - 1).Name = "UserForm" Then Unload VBA.UserForms(i - 1)
Exit Sub
Next
With UserForm
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.3 * .Height)
.Show
End With
End Sub
Sub StoreUserformCode1()
Dim txtFrame As TextFrame
Set txtFrame = Sheets("Shipping").Shapes("Rounded Rectangle 1").TextFrame
If txtFrame.Characters.Text = "Close UF" Then
Unload UserForm
txtFrame.Characters.Text = "UserForm"
Exit Sub
Else
With UserForm
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.3 * .Height)
.Show
End With
End If
txtFrame.Characters.Text = "Close UF"
End Sub
Sub StoreUserformCode2()
Dim txtFrame As TextFrame
Set txtFrame = Sheets("Shipping").Shapes("Rounded Rectangle 1").TextFrame
If txtFrame.Characters.Text = "Close UF" Then
Unload UserForm
txtFrame.Characters.Text = "UserForm"
Exit Sub
Else
txtFrame.Characters.Text = "Close UF"
With UserForm
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.3 * .Height)
.Show
End With
End If
End Sub
Sub UserForm()
Dim i As Integer
'Typical approach for zero based collection is to use For i = 0 To [collection].Count-1
'If there is only 1 form open that counter will become For i = 0 to 0 (because of 1-1)
'This approach makes the counter from 1 to 1 when only 1 form is open
'and Userforms(i-1) produces the correct zero based starting point for the collection
'If count = 0 then no form is open, skip to With block, else test if open form name is UserForm.
'If true, close it and exit sub
For i = 1 To VBA.UserForms.Count
If VBA.UserForms(i - 1).Name = "UserForm" Then Unload VBA.UserForms(i - 1)
Exit Sub
Next
With UserForm
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.3 * .Height)
.Show
End With
End Sub
Sub StoreUserformCode1()
Dim txtFrame As TextFrame
Set txtFrame = Sheets("Shipping").Shapes("Rounded Rectangle 1").TextFrame
If txtFrame.Characters.Text = "Close UF" Then
Unload UserForm
txtFrame.Characters.Text = "UserForm"
Exit Sub
Else
With UserForm
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.3 * .Height)
.Show
End With
End If
txtFrame.Characters.Text = "Close UF"
End Sub
Sub StoreUserformCode2()
Dim txtFrame As TextFrame
Set txtFrame = Sheets("Shipping").Shapes("Rounded Rectangle 1").TextFrame
If txtFrame.Characters.Text = "Close UF" Then
Unload UserForm
txtFrame.Characters.Text = "UserForm"
Exit Sub
Else
txtFrame.Characters.Text = "Close UF"
With UserForm
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.3 * .Height)
.Show
End With
End If
End Sub