Vba 如何将工作簿隐藏在userform后面?
我尝试了多种方法将特定工作簿隐藏在userform后面 我最后使用的代码如下:Vba 如何将工作簿隐藏在userform后面?,vba,excel,userform,visible,Vba,Excel,Userform,Visible,我尝试了多种方法将特定工作簿隐藏在userform后面 我最后使用的代码如下: 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 Applicatio
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
它会将应用程序窗口隐藏在userform后面,但如果有多个工作簿打开,并且我激活了其中一个工作簿,那么当我随后单击userform时,它将只在userform中移动活动工作簿
如何指示始终使用此功能仅影响特定工作簿
此外,通过从一个UF跳到另一个UF,每次都会执行相同的代码
基本上,我需要将特定工作簿始终隐藏在userform后面,并且用户无法访问,但所有其他已打开的工作簿或我打算打开的工作簿不得受此影响!如果我使用此功能或类似功能,其他工作簿必须可访问、可见且不应显示或移动
我还尝试了application.visible=false,但这很危险,因为它还会影响其他工作簿,并且应用程序在任务栏上不可见,任何错误都可能导致应用程序在后台打开,用户看不到它
如果您建议任何其他方法来达到上述要求,我很乐意尝试
Thnx尝试隐藏窗体的父窗口
Private Sub UserForm_Initialize()
ThisWorkbook.Windows(1).Visible = False
End Sub
Private Sub UserForm_Terminate()
ThisWorkbook.Windows(1).Visible = True
End Sub
或者确定窗体的屏幕坐标并将其应用于父窗体
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
要获得屏幕分辨率,请使用:
杰出的我做了一些小的修改,但这只是我需要的。
#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