Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA将X行调整到Excel屏幕_Vba_Excel - Fatal编程技术网

使用VBA将X行调整到Excel屏幕

使用VBA将X行调整到Excel屏幕,vba,excel,Vba,Excel,我目前正在excel工作簿上编写一个小VBA代码,以自动显示日志。因此,我的工作簿中有两张工作表。其中一个显示按紧急情况排序的当前日志。另一个显示给定部门的新日志。工作簿连接到我们的日志数据库,并通过SQL数据库上的视图每5分钟刷新一次数据。我的问题是,目前,我确实设置了行高以适合我的屏幕。我需要确保行高度被动态设置为始终显示相同数量的行。例如,如果用户希望能够看到5行,我希望他能够看到(通过我创建的表单)。然后,我会使用一个滚动5行。这是我的代码: 'Check how many "Urgen

我目前正在excel工作簿上编写一个小VBA代码,以自动显示日志。因此,我的工作簿中有两张工作表。其中一个显示按紧急情况排序的当前日志。另一个显示给定部门的新日志。工作簿连接到我们的日志数据库,并通过SQL数据库上的视图每5分钟刷新一次数据。我的问题是,目前,我确实设置了行高以适合我的屏幕。我需要确保行高度被动态设置为始终显示相同数量的行。例如,如果用户希望能够看到5行,我希望他能够看到(通过我创建的表单)。然后,我会使用一个滚动5行。这是我的代码:

'Check how many "Urgent" Logs are showing
Dim XRange As Range
  Set XRange = Cells(Rows.Count, 4).End(xlUp)
  Set XRange = Range(Range("C1"), XRange)
  AnswerUrgent = Application.CountIf(XRange, "Urgent")

'Check how many "High" Logs are showing
Dim YRange As Range
  Set YRange = Cells(Rows.Count, 4).End(xlUp)
  Set YRange = Range(Range("C1"), YRange)
  AnswerHigh = Application.CountIf(YRange, "High")

'Check how many logs to show
  TotalAns = AnswerUrgent + AnswerHigh

  For X = 1 To (Round(TotalAns / 4) + 1)
    If X > 1 Then
      ActiveWindow.SmallScroll Down:=ScrollBy '(move down by 4 rows)
    End If

'Responsive sleep is to sleep and do events after each 250MS so the form will be
'accessible
' *4 to get 1 sec
    ResponsiveSleep (DelayInSec * 4)
  Next X
我想做的是让它充满活力。如果用户选择显示5行,我希望能够显示其中的5行并滚动5行

不过我不想把整张纸都放大。我的意思是我不想用变焦来让整个床单适合我的屏幕


谢谢

我找到了这样做的方法。。。我决定找到一种全屏(没有标题栏和所有内容)的方法,因此我可以使用以下内容:

Sub FormatWindow(ScrollBy)



    Dim Xres As Integer
    Dim Yres As Integer
    Dim MaxXPoint As Single
    Dim MaxYpoint As Single
    Dim RowHeightForFour As Integer



Xres = GetSystemMetrics(SM_CXSCREEN)
Yres = GetSystemMetrics(SM_CYSCREEN)


'1 pixel = 0.75 Point
MaxXPoint = (Xres * 0.75)
MaxYpoint = (Yres * 0.75)

'Set the first row to 5% of screen
PointForFirstRow = ((MaxYpoint * 5) / 100)

'Get the rest of the space to display rows
MaxPointAfterFirstRow = MaxYpoint - ((MaxYpoint * 5) / 100)


'Set the first row to take 5% of the total displayable Y resolution
ActiveSheet.Rows(1).RowHeight = PointForFirstRow

'Get how many points per row
PointPerRow = MaxPointAfterFirstRow / ScrollBy

            Dim ws As Worksheet
            For Each ws In Worksheets

'If the sheet's name is not "Start", Apply the Height to all the rows.
            If Not (ws.Name = "Start") Then
            ws.Range("A2:A" & ws.Rows.Count).RowHeight = PointPerRow
            End If

            Next ws

End Sub

希望这对其他人有帮助

我找到了这样做的方法。。。我决定找到一种全屏(没有标题栏和所有内容)的方法,因此我可以使用以下内容:

Sub FormatWindow(ScrollBy)



    Dim Xres As Integer
    Dim Yres As Integer
    Dim MaxXPoint As Single
    Dim MaxYpoint As Single
    Dim RowHeightForFour As Integer



Xres = GetSystemMetrics(SM_CXSCREEN)
Yres = GetSystemMetrics(SM_CYSCREEN)


'1 pixel = 0.75 Point
MaxXPoint = (Xres * 0.75)
MaxYpoint = (Yres * 0.75)

'Set the first row to 5% of screen
PointForFirstRow = ((MaxYpoint * 5) / 100)

'Get the rest of the space to display rows
MaxPointAfterFirstRow = MaxYpoint - ((MaxYpoint * 5) / 100)


'Set the first row to take 5% of the total displayable Y resolution
ActiveSheet.Rows(1).RowHeight = PointForFirstRow

'Get how many points per row
PointPerRow = MaxPointAfterFirstRow / ScrollBy

            Dim ws As Worksheet
            For Each ws In Worksheets

'If the sheet's name is not "Start", Apply the Height to all the rows.
            If Not (ws.Name = "Start") Then
            ws.Range("A2:A" & ws.Rows.Count).RowHeight = PointPerRow
            End If

            Next ws

End Sub

希望这对其他人有帮助

我不认为有一种本地方式可以在Excel中修改滚动条本身,在userform中创建滚动条没有帮助吗?目标是创建滚动条本身。这是一个“仅查看”屏幕,将显示日志。是否有办法获得最大可显示高度?绝对值还是像素值?这可能有助于我找到可显示的总行数(我想要的高度/行数)。我不认为有一种本地方法可以在Excel中修改滚动条本身,这无助于在userform中创建滚动条吗?目标是创建滚动条本身。这是一个“仅查看”屏幕,将显示日志。是否有办法获得最大可显示高度?绝对值还是像素值?这可以帮助我找到可显示的总行数(高度/所需行数)。