Страницы: 1
RSS
Как разместить UserForm по центру экрана при условии, что сама книга 1px*1px в левом верхнем углу ?
 
Доброго времени суток! Подскажите, пожалуйста, код для события на открытие книги, которые разместит либо саму книгу ровно в центре экрана либо userform, который открывается при открытии книги.
Спасибо!
Улыбнись.
 
Установите свойство StartupPosition формы равное 2 (по ссылке есть и пример).
Изменено: sokol92 - 29.07.2019 14:45:38
Владимир
 
Решение:
Код
Private Sub Workbook_Open()
    Dim maxWidth As Integer
    Dim maxHeight As Integer
    Application.WindowState = xlMaximized
    maxWidth = Application.Width
    maxHeight = Application.Height
    Call CenterApp(maxWidth, maxHeight)
End Sub

Sub CenterApp(maxWidth As Integer, maxHeight As Integer)
    Dim appLeft As Integer
    Dim appTop As Integer
    Dim appWidth As Integer
    Dim appHeight As Integer
    Application.WindowState = xlNormal
    appLeft = maxWidth / 2
    appTop = maxHeight / 2
    appWidth = maxWidth / 16
    appHeight = maxHeight / 30
    Application.Left = appLeft
    Application.Top = appTop
    Application.Width = appWidth
    Application.Height = appHeight
End Sub
Изменено: falmrom - 29.07.2019 16:19:56
Улыбнись.
Страницы: 1
Наверх