Чтобы найти номер страницы в VBA, вы можете использовать различные методы в зависимости от контекста. Вот несколько примеров:
-
Использование метода Find в объекте Range:
Dim pageNumber As Long Dim searchString As String searchString = "Page 10" ' Replace with the desired search term With ActiveSheet.UsedRange Set foundCell = .Find(What:=searchString, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False) If Not foundCell Is Nothing Then pageNumber = foundCell.Page MsgBox "Page number: " & pageNumber Else MsgBox "Page number not found." End If End With
-
Использование метода Find в объекте Worksheet:
Dim pageNumber As Long Dim searchString As String searchString = "Page 10" ' Replace with the desired search term With ActiveSheet Set foundCell = .Cells.Find(What:=searchString, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False) If Not foundCell Is Nothing Then pageNumber = foundCell.Page MsgBox "Page number: " & pageNumber Else MsgBox "Page number not found." End If End With
-
Использование цикла для обхода каждого листа:
Dim pageNumber As Long Dim searchString As String searchString = "Page 10" ' Replace with the desired search term For Each ws In ThisWorkbook.Worksheets With ws.UsedRange Set foundCell = .Find(What:=searchString, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False) If Not foundCell Is Nothing Then pageNumber = foundCell.Page MsgBox "Page number: " & pageNumber & " in worksheet " & ws.Name Exit For End If End With Next ws
Это всего лишь несколько примеров того, как найти номер страницы в VBA. Вы можете изменить их в соответствии со своими требованиями.