none
Can VBA change pages in Microsoft Word's “Read Mode” Layout? RRS feed

  • Question

  • I'm trying to change pages while Microsoft Word is in "Read Mode"* by using a VBA code, and I can't seem to find any function that allows that.

    (* Please notice that I'm talking about the "Read Mode" layout that you can change with the bottom-right icons in word, and not the "Read Only" mode that you sometimes get when you open a document from an unknown source)

    In "Print Layout" it is simple since I can use something like -

    Selection.GoTo What:=wdGoToBookmark, Name:="LastReadingPoint"

    But It won't work while I'm in "Read Mode".

    None of these work:
    ActiveDocument.GoTo What:=wdGoToPage, which:=wdGoToAbsolute, Count:=1
    ActiveDocument.Range.GoTo What:=wdGoToPage, which:=wdGoToAbsolute, Count:=1
    Selection.GoTo What:=wdGoToBookmark, Name:="LastReadingPoint"
    ActiveDocument.Range.GoTo What:=wdGoToBookmark, Name:="LastReadingPoint"
    ActiveDocument.Range.GoToNext wdGoToPage
    ActiveDocument.GoTo What:=wdGoToBookmark, Name:="LastReadingPoint"

    (LastReadingPoint is a bookmark I've added to the text)

    Any ideas or hacks?
    Thursday, May 16, 2019 3:36 PM

Answers

  • Hi,
    I suggest using Pane.PageScroll, Pane.LargeScroll, Pane.SmallScroll method.

    Option Explicit
    
    Public Sub Sample()
      NavigatePageInReadMode 15 'move to 15 page.
    End Sub
    
    Private Sub NavigatePageInReadMode(ByVal TargetPageNum As Long)
      Dim curtPageNum As Long
      
      If ActiveWindow.View.Type = wdReadingView Then
        With ActiveWindow.ActivePane
          curtPageNum = .Selection.Information(wdActiveEndPageNumber)
          If TargetPageNum > curtPageNum Then
            .PageScroll Down:=TargetPageNum - curtPageNum
          ElseIf TargetPageNum < curtPageNum Then
            .PageScroll Up:=curtPageNum - TargetPageNum
          End If
        End With
      End If
    End Sub

    Best regards,
    kinuasa
    • Marked as answer by MennyB Thursday, May 23, 2019 9:15 PM
    Thursday, May 23, 2019 4:56 AM

All replies

  • Hi,
    I suggest using Pane.PageScroll, Pane.LargeScroll, Pane.SmallScroll method.

    Option Explicit
    
    Public Sub Sample()
      NavigatePageInReadMode 15 'move to 15 page.
    End Sub
    
    Private Sub NavigatePageInReadMode(ByVal TargetPageNum As Long)
      Dim curtPageNum As Long
      
      If ActiveWindow.View.Type = wdReadingView Then
        With ActiveWindow.ActivePane
          curtPageNum = .Selection.Information(wdActiveEndPageNumber)
          If TargetPageNum > curtPageNum Then
            .PageScroll Down:=TargetPageNum - curtPageNum
          ElseIf TargetPageNum < curtPageNum Then
            .PageScroll Up:=curtPageNum - TargetPageNum
          End If
        End With
      End If
    End Sub

    Best regards,
    kinuasa
    • Marked as answer by MennyB Thursday, May 23, 2019 9:15 PM
    Thursday, May 23, 2019 4:56 AM
  • Amazing. 

    I only needed this line: ActiveWindow.ActivePane.PageScroll down:=1

    But since I couldn't find it, this was the workaround I created:   

    Word.Application.Activate
    SendKeys ("{RIGHT}")
    BTN_IncPage.SetFocus
    But your solution is clearly superior.

    Thursday, May 23, 2019 9:18 PM