Уважаемые, подскажите, пожалуйста, каким образом можно заставить лист excel разворачиваться на весь экран при окрытии книга? |
|
KuklP Пользователь Сообщений: 14868 E-mail и реквизиты в профиле. |
В модуль книги: Я сам — дурнее всякого примера! … |
{quote}{login=KukLP}{date=14.10.2011 11:25}{thema=}{post}В модуль книги: |
|
KuklP Пользователь Сообщений: 14868 E-mail и реквизиты в профиле. |
А у меня разворачивается. Макросы разрешены? Я сам — дурнее всякого примера! … |
{quote}{login=KukLP}{date=14.10.2011 11:49}{thema=}{post}А у меня разворачивается. Макросы разрешены?{/post}{/quote} |
|
nerv Пользователь Сообщений: 3071 |
Макрорекодер: Application.WindowState = xlMaximized : ) |
KuklP Пользователь Сообщений: 14868 E-mail и реквизиты в профиле. |
Саня вопрос был о листе, а не о приложении. Хотя может Black__Hole именно это и надо? Я сам — дурнее всякого примера! … |
Black__Hole Пользователь Сообщений: 259 |
#8 14.10.2011 15:22:14 {quote}{login=nerv}{date=14.10.2011 12:00}{thema=}{post}Макрорекодер: Application.WindowState = xlMaximized : ){/post}{/quote} |
Установка состояния окна приложения Excel из кода VBA с помощью свойства Application.WindowState. Сворачивание и разворачивание окна. Чтение данных о состоянии окна.
Application.WindowState — это свойство, которое задает или возвращает состояние окна приложения Excel.
Состояние окна приложения Excel задается константой из коллекции XlWindowState, при чтении информации о состоянии окна — свойство Application.WindowState возвращает числовое значение константы.
Свойство Application.WindowState позволяет развернуть окно приложения Excel из кода VBA на весь экран — до максимального размера, свернуть окно «в иконку» или задать ему нормальные размеры, установленные ранее, развернув из свернутого или свернув из максимального.
Синтаксис свойства WindowState объекта Application:
Константы XlWindowState
Константы из коллекции XlWindowState:
Константа | Значение | Описание |
---|---|---|
xlMaximized | -4137 | Максимальное окно (развернуто на весь экран) |
xlMinimized | -4140 | Минимальное окно (свернуто «в иконку») |
xlNormal | -4143 | Нормальное окно (размеры, установленные ранее) |
Пример кода с WindowState
Пример записи и чтения свойства Application.WindowState:
Sub Test() ‘Запись свойства WindowState Application.WindowState = xlMaximized ‘или -4137 ‘Application.WindowState = xlMinimized ‘или -4140 ‘Application.WindowState = xlNormal ‘или -4143 ‘Проверка, в каком состоянии находится окно приложения MsgBox Application.WindowState End Sub |
Попробуйте по очереди задавать разные константы свойству Application.WindowState и смотрите, какое значение будет считано. У меня получились удивительные результаты при выполнении строк кода по очереди, как в примере:
Application.WindowState = xlMinimized
— MsgBox возвращает совсем не -4140;- после первого запуска
Application.WindowState = xlNormal
— окно приложения разворачивается на весь экран, после второго запуска — переходит к нормальному состоянию.
Не удалось мне добиться значения -4140 и при минимизации окна вручную, разместив предварительно следующий код в модуль книги:
Private Sub Workbook_WindowResize(ByVal Wn As Window) MsgBox Application.WindowState End Sub |
0 / 0 / 0 Регистрация: 05.07.2020 Сообщений: 130 |
|
1 |
|
Разворачивание книги на весь экран06.09.2021, 13:08. Показов 1646. Ответов 5
Здравствуйте.
0 |
695 / 236 / 18 Регистрация: 17.01.2011 Сообщений: 583 Записей в блоге: 1 |
|
06.09.2021, 19:47 |
2 |
Дёшево и сердито:
0 |
0 / 0 / 0 Регистрация: 05.07.2020 Сообщений: 130 |
|
12.09.2021, 17:37 [ТС] |
3 |
dzug, не записывается так макрос.
0 |
dzug 695 / 236 / 18 Регистрация: 17.01.2011 Сообщений: 583 Записей в блоге: 1 |
||||
12.09.2021, 18:27 |
4 |
|||
У меня реагирует:
1 |
Narimanych 2632 / 1637 / 745 Регистрация: 23.03.2015 Сообщений: 5,149 |
||||
12.09.2021, 20:49 |
5 |
|||
Решениеplank1433,
1 |
0 / 0 / 0 Регистрация: 05.07.2020 Сообщений: 130 |
|
13.09.2021, 06:26 [ТС] |
6 |
Ясно. Спасибо
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
13.09.2021, 06:26 |
6 |
Workbook_Activate will bring full screen mode while other will bring back normal mode.
Private Sub Workbook_Activate()
On Error Resume Next
With Application
.DisplayFullScreen = True
.CommandBars("Worksheet Menu Bar").Enabled = False
End With
End Sub
Private Sub Workbook_Deactivate()
On Error Resume Next
With Application
.DisplayFullScreen = False
.CommandBars("Worksheet Menu Bar").Enabled = True
End With
End Sub
EDIT
you shouldn’t ‘modify’ the way Windows works at a system level. However, if you really, really must; add the following to a new module and call the SetStyle procedure.
That code is offered UNTESTED‘as is’ — the API is a way to modify Windows at a system level and can be dangerous (sudden crashes, data file corruption…) if you do not know what you are doing.
VB:
Option Explicit
'Related Windows API functions
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long
'Window style constants
Private Const GWL_STYLE As Long = (-16) '// The offset of a window's style
Private Const GWL_EXSTYLE As Long = (-20) '// The offset of a window's extended style
Private Const WS_CAPTION As Long = &HC00000 '// Title bar bit
Private Const WS_SYSMENU As Long = &H80000 '// System menu bit
Private Const WS_THICKFRAME As Long = &H40000 '// Sizable frame bit
Private Const WS_MINIMIZEBOX As Long = &H20000 '// Minimize box bit
Private Const WS_MAXIMIZEBOX As Long = &H10000 '// Maximize box bit
Private Const WS_EX_TOOLWINDOW As Long = &H80 '// Tool Window: small titlebar bit
'Constant to identify the Close menu item
Private Const SC_CLOSE As Long = &HF060
Public Sub SetStyle()
Dim lStyle As Long, hMenu As Long
'Get the basic window style
lStyle = GetWindowLong(Application.hWnd, GWL_STYLE)
If lStyle = 0 Then
MsgBox "Unable to determine application window handle...", vbExclamation, "Error"
Exit Sub
End If
'// Build up the basic window style flags for the form
'// Uncomment the features you want...
'// Set it True to enable, FALSE to disable
'// The first 2 are obvious, ThickFrame controls if the Window is sizable or not.
'// SetBit lStyle, WS_CAPTION, True
'// SetBit lStyle, WS_SYSMENU, False
'// SetBit lStyle, WS_THICKFRAME, False
SetBit lStyle, WS_MINIMIZEBOX, False
SetBit lStyle, WS_MAXIMIZEBOX, False
'Set the basic window styles
SetWindowLong Application.hWnd, GWL_STYLE, lStyle
'Get the extended window style
lStyle = GetWindowLong(Application.hWnd, GWL_EXSTYLE)
'// Handle the close button differently
'// If Close button is wanted
'// hMenu = GetSystemMenu(Application.hWnd, 1)
'// Not wanted - delete it from the control menu
hMenu = GetSystemMenu(Application.hWnd, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
'Update the window with the changes
DrawMenuBar Application.hWnd
SetFocus Application.hWnd
End Sub
'// Set or clear a bit from a style flag
Private Sub SetBit(ByRef lStyle As Long, ByVal lBit As Long, ByVal bOn As Boolean)
If bOn Then
lStyle = lStyle Or lBit
Else
lStyle = lStyle And Not lBit
End If
End Sub
Excel’s toolbar and Ribbon contain many features and shortcut icons that are aimed for improving productivity. On the other hand, these icons actually take a lot of space in your screen. Thus, your work space becomes a bit more limited. A full screen, or close-to-full-screen view can greatly increase the work area visibility. In this guide, we’re going to show you how to switch to Excel full screen mode.
Excel versions have different type of full screen approaches. Let’s see them all.
Switch full screen mode in Excel 2016 and higher versions
Shortcut
When the Excel window is active, press Ctrl + Shift + F1 on your keyboard to switch full screen. Although, the Mac version doesn’t have a dedicated shortcut, you can use the generic Control + Command + F to make the window full screen. However, the Ribbon will stay.
Ribbon Icon
By default, Excel doesn’t have the Full Screen icon in the Ribbon. However, this command can be added manually. Follow the steps to open Excel Options and add the command into the Ribbon.
- Right-click on the Ribbon and click on the Customize the Ribbon, or go to File > Excel Options > Customize Ribbon
- Select All Commands in Choose commands from dropdown
- Scroll down to the commands list until you find Full Screen and select it
- Click the New Tab button on the right side of the window to add a new tab into the Ribbon. Excel also adds a group under the new tab.
- Optionally you can rename the new tab and the group using Rename
- Click Add when Full Screen is selected
- Click OK to apply your changes
After these steps, you can find the Full Screen command under the new tab in the Ribbon.
VBA Code
Another way to enable or disable the full screen mode is using a simple VBA code. The Application.DisplayFullScreen property value defines the full screen mode. Give True to switch to full screen. Alternatively, you can set it to False to return back to the normal view.
Here are sample codes:
Sub Fullscreen_On() Application.DisplayFullScreen = True End Sub Sub Fullscreen_Off() Application.DisplayFullScreen = False End Sub
Switch full screen mode in Excel 2013
Excel 2013 actually does not support a full screen mode, and we do not know why it may have been removed from the 2013 version. However, you can hide the formula bar and the Ribbon to mimic the same functionality.
To hide the Ribbon, press the Ctrl + F1 keys, or right-click on the Ribbon and click on the Collapse the Ribbon item.
You can find the option for hiding the formula bar on the View tab. Uncheck the Formula Bar checkbox to hide.
You can inf more information about hiding the formula bar in How to hide and unhide formula bar in Excel.
Switch full screen mode in Excel 2007 or 2010
The Full Screen command can be found on the View tab in the Ribbon.
Press the Esc key to exit from the full screen mode.