How to Get Windows Display Resolution for PowerPoint Monitor in VBA
Question details
The user needs to retrieve the actual configured Windows display resolution (e.g., 1920x1080) for the specific monitor displaying a PowerPoint window using VBA, rather than getting the physical monitor pixels.

- Product
- PowerPoint
- Device & OS
- Windows
- Scenario
- Developing a PowerPoint macro that requires accurate monitor resolution data to correctly size, position, or scale presentation elements on a specific display.
- Observed behavior
- Standard VBA approaches like GetSystemMetrics or GetDesktopWindow return the monitor's physical pixel dimensions, which do not reflect the user's active configured display resolution or scaling.
Ensure you are familiar with inserting Windows API declarations in the VBA Editor and check whether your Office installation is 32-bit or 64-bit to use the correct PtrSafe keywords and LongPtr data types.
Use EnumDisplaySettings and MonitorFromWindow APIs
Combine specific Windows APIs to pinpoint the active monitor hosting the application and extract its configured display resolution.
Standard functions like GetSystemMetrics only return physical monitor pixels. To get the configured resolution, you must use Windows APIs to identify the monitor handle, get its system device name, and query its current device mode settings.
Open the VBA Editor (ALT + F11), insert a new Module, and declare MonitorFromWindow, GetMonitorInfo, and EnumDisplaySettings. Ensure you use PtrSafe if running 64-bit Office.
Create the necessary custom VBA types (DEVMODE and MONITORINFOEX) within your module to store the display settings data accurately.
Use MonitorFromWindow alongside the PowerPoint application's HWND property to capture the handle of the exact monitor currently displaying the presentation window.
Call the EnumDisplaySettings API passing ENUM_CURRENT_SETTINGS, then read the DEVMODE.dmPelsWidth and DEVMODE.dmPelsHeight properties to get the active configured width and height.

Create and Run VBA Macros Seamlessly in WPS Presentation
WPS Office provides robust VBA support, allowing you to execute complex Windows API calls and automate your presentations exactly as you would in Microsoft PowerPoint.
- 1. Open WPS Presentation: Launch WPS Office and open your macro-enabled presentation file (.pptm or .pptx).
- 2. Access the Developer Tools: Navigate to the 'Developer' tab on the top ribbon and click on 'VBA Editor' to open the coding environment.
- 3. Insert your API code: Insert a new module, paste your Windows API declarations for monitor resolution, and run your macro seamlessly.

Frequently Asked Questions
Why does GetSystemMetrics return physical pixels instead of the display resolution?
GetSystemMetrics retrieves the dimensions of the primary display or virtual screen based on raw physical pixels. It often ignores custom user display scaling (like 125% or 150%) or specific multi-monitor virtual resolutions.
Can I use this VBA method in 64-bit Office versions?
Yes, but you must ensure your API declarations are updated for 64-bit compatibility. Use the 'PtrSafe' keyword in your Declare statements and ensure handles (like HWND) are typed as 'LongPtr' instead of 'Long'.
How do I find the HWND of my PowerPoint window in VBA?
You can retrieve the active window handle in PowerPoint by using the 'HWND' property of the 'ActiveWindow' object, or by utilizing the FindWindow API function to locate the PowerPoint application frame class.
Will this code work if my presentation spans multiple monitors?
The MonitorFromWindow API determines the monitor that has the largest area of intersection with the specified window. It will return the resolution of whichever monitor contains the majority of the PowerPoint window.




