如何将工作簿隐藏在用户窗体的后面? [英] How to hide workbook behind userform?

查看:69
本文介绍了如何将工作簿隐藏在用户窗体的后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了多种方法将特定的工作簿隐藏在用户窗体的后面!

我使用的最后一个代码在这里:

 私有子UserForm_Layout()Application.Left = MainWindow.LeftApplication.Top = MainWindow.Top结束子私人子UserForm_Activate()Application.Left = Me.LeftApplication.Top =我.TopApplication.Width = Me.Width * 0.85Application.Height = Me.Height * 0.85结束子 

它将在用户窗体后面隐藏应用程序窗口,但是如果有多个工作簿打开并且我激活了其中一个,则当我单击用户窗体之后,它将仅在用户窗体内移动活动的工作簿!

如何指示始终使用此功能仅影响特定的工作簿?

此外,每次从一个UF跳转到另一个相同的代码都将被执行!

基本上,我需要始终将特定的工作簿隐藏在用户窗体的后面,并且不能被用户访问,但是所有其他已打开的工作簿或我打算打开的工作簿都不会受到此影响!其他工作簿必须是可访问的且可见的,并且不应消失,如果我使用此功能或类似功能,则不要移动!

我还尝试了application.visible = false,但是这很危险,因为它还会影响其他工作簿,并且应用程序在任务栏上不可见,而且任何错误都可能导致应用程序在后台打开并且对用户不可见!

如果您建议采用任何其他方法来达到上述要求,我将很乐意尝试!

Thnx

解决方案

尝试隐藏表单的父窗口

  Private子UserForm_Initialize()ThisWorkbook.Windows(1).Visible = False结束子私人子UserForm_Terminate()ThisWorkbook.Windows(1).Visible = True结束子 

或确定表单的屏幕坐标,然后将其应用于父级

  Private子UserForm_Initialize()使用ThisWorkbook.Windows(1).WindowState = xlNormal.Left = Me.Left + Application.Left'计算精确的Screen.Left坐标.Top = Me.Top + Application.Top'计算精确的屏幕.Top坐标.Width = Me.Width * 0.85高度=身高* 0.85结束于结束子 


.

要获取屏幕分辨率,请使用 GetSystemMetrics函数:


  #If VBA7然后声明PtrSafe函数GetSystemMetrics32库"user32"别名"GetSystemMetrics" _(ByVal nIndex尽可能长)#别的声明函数GetSystemMetrics32 Lib"user32"别名"GetSystemMetrics" _(ByVal nIndex尽可能长)#万一公共常量SM_CXSCREEN = 0公共常量SM_CYSCREEN = 1私有子setMonitors()celTotalMonitors = GetSystemMetrics32(80)结束子私有子setResolution()'虚拟屏幕的宽度,以像素为单位celScreenResolutionX = Format(GetSystemMetrics32(78),#,## 0")'虚拟屏幕的高度,以像素为单位celScreenResolutionY = Format(GetSystemMetrics32(79),#,## 0")'celScreenResolutionY = celScreenResolutionY.Value \ celTotalMonitors结束子 

I've tried multiple methods to hide specific workbook behind userform!

Last code I've used is here:

Private Sub UserForm_Layout()
  Application.Left = MainWindow.Left
  Application.Top = MainWindow.Top
End Sub
Private Sub UserForm_Activate()
  Application.Left = Me.Left
  Application.Top = Me.Top
  Application.Width = Me.Width * 0.85
  Application.Height = Me.Height * 0.85
End sub

It will hide application window behind userform, but if there is multiple workbooks open and I activate one of them, when I click on userform afterwards, it will move only active workbook within userform!

How to instruct to always affect only specific workbook with this function?

Also, by jumping from one UF to another same code will be executed each time!

Basically, I need to have specific workbook hidden behind userform ALWAYS and not accessible by users, but all other already opened workbooks or workbooks I intend to open must not be affected by this! Other workbooks must be accessible, and visible and shouldn't dissappear, or move if I use this or similar function!

I also tried application.visible = false but, it is dangerous as it also affects other workbooks and application is OFC not visible on taskbar, and any error may cause application to left open in background and not visible by user!

If you suggest any other method to achieve above mentioned requirement I would be happy to try it!

Thnx

解决方案

Try hiding the form's parent window

Private Sub UserForm_Initialize()
    ThisWorkbook.Windows(1).Visible = False
End Sub

Private Sub UserForm_Terminate()
    ThisWorkbook.Windows(1).Visible = True
End Sub

Or determine screen coordinates of the form and apply them the parent

Private Sub UserForm_Initialize()
    With ThisWorkbook.Windows(1)
        .WindowState = xlNormal
        .Left = Me.Left + Application.Left  'Calculate exact Screen.Left coordinate
        .Top = Me.Top + Application.Top     'Calculate exact Screen.Top coordinate
        .Width = Me.Width * 0.85
        .Height = Me.Height * 0.85
    End With
End Sub


.

To get screen resolution use GetSystemMetrics function:


#If VBA7 Then
    Declare PtrSafe Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" _
    (ByVal nIndex As Long) As Long
#Else
    Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" _
    (ByVal nIndex As Long) As Long
#End If
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1



Private Sub setMonitors()

    celTotalMonitors = GetSystemMetrics32(80)

End Sub



Private Sub setResolution()

    'The width of the virtual screen, in pixels
    celScreenResolutionX = Format(GetSystemMetrics32(78), "#,##0")

    'The height of the virtual screen, in pixels
    celScreenResolutionY = Format(GetSystemMetrics32(79), "#,##0")

    'celScreenResolutionY = celScreenResolutionY.Value \ celTotalMonitors
End Sub

这篇关于如何将工作簿隐藏在用户窗体的后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆