Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-17-2024, 01:53 AM
gmayor's Avatar
gmayor gmayor is offline Word Macro issue: Insert specific page between pages Windows 10 Word Macro issue: Insert specific page between pages Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Bearing in mind that there are no 'pages' in a Word document, if your selected range is in a table. then the following is an example of code to move the selection before the table.


Code:
 Dim orng As Range
 Dim oTable As Table
    Set orng = Selection.Range
    If orng.Information(wdWithInTable) = True Then
        Set oTable = orng.Tables(1)
        orng.Start = oTable.Range.Start
        orng.Collapse 1
        orng.Select
        Selection.SplitTable
        Set orng = Selection.Range
        orng.Text = "The selection is before the table"
    Else
        orng.Text = "The selection is not in a table"
    End If
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 02-19-2024, 06:43 AM
syl3786 syl3786 is offline Word Macro issue: Insert specific page between pages Windows 10 Word Macro issue: Insert specific page between pages Office 2019
Advanced Beginner
Word Macro issue: Insert specific page between pages
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Bearing in mind that there are no 'pages' in a Word document, if your selected range is in a table. then the following is an example of code to move the selection before the table.
Code:
 Dim orng As Range
 Dim oTable As Table
    Set orng = Selection.Range
    If orng.Information(wdWithInTable) = True Then
        Set oTable = orng.Tables(1)
        orng.Start = oTable.Range.Start
        orng.Collapse 1
        orng.Select
        Selection.SplitTable
        Set orng = Selection.Range
        orng.Text = "The selection is before the table"
    Else
        orng.Text = "The selection is not in a table"
    End If
Thank you so much for your invaluable assistance! It's truly a pleasure to be in the presence of someone as skilled in VBA as yourself!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Macro issue: Insert specific page between pages Word Macro VBA | Insert images one by one, page by page leonelcd Word VBA 1 11-05-2023 03:28 PM
Printing Specific Page Issue FCUCCMV Word 2 03-07-2022 07:15 AM
Word Macro issue: Insert specific page between pages Macro for word to add page break and specific text to end of document pizzaman1 Word VBA 6 11-14-2014 11:25 PM
Word Macro issue: Insert specific page between pages Macro to insert multiple pictures to word to a specific size and text wrap mescaL Word VBA 3 11-03-2014 10:51 PM
Word Macro issue: Insert specific page between pages Selection of all Text for a specific page in word is spanning selection across pages ramsgarla Word VBA 9 12-05-2012 03:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft