Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2021, 03:09 PM
AVarg123 AVarg123 is offline Move table using VBA Windows 10 Move table using VBA Office 2016
Novice
Move table using VBA
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default Move table using VBA

Hi, I have a table (6 rows, 2 columns) at the bottom of page 4. I need to move the table to the first page when user opens the document. I also have eight checkboxes in the same document. All unchecked boxes should be hidden when user close the document. Any suggestion? Thankyou!
Reply With Quote
  #2  
Old 12-14-2021, 10:29 PM
gmayor's Avatar
gmayor gmayor is offline Move table using VBA Windows 10 Move table using VBA 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

What type of check boxes? Content controls? Form Fields? ActiveX controls?
Is this the only table in the document?

Is it in the footer of page 4 or on the main page?
Is page 4 the last page of the document?
__________________
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
  #3  
Old 12-15-2021, 10:35 AM
AVarg123 AVarg123 is offline Move table using VBA Windows 10 Move table using VBA Office 2016
Novice
Move table using VBA
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default

Hi Graham, All checkboxes are ActiveX Controls. Including this, there are 13 tables in the document. Sorry, there are 5 pages and this table is on the main page on page 5 and it is the last page.
Reply With Quote
  #4  
Old 12-16-2021, 01:19 AM
gmayor's Avatar
gmayor gmayor is offline Move table using VBA Windows 10 Move table using VBA 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

Without access to the document, I think the following should work:
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 16 Dec 2021
Dim oTable As Table
Dim oRng As Range
Dim oCtrl As InlineShape
Dim oCheck As Object

    Set oTable = ActiveDocument.Tables(ActiveDocument.Tables.Count)
    Set oRng = ActiveDocument.Range(0, 0)
    oRng.FormattedText = oTable.Range.FormattedText
    oRng.Select
     oTable.Delete


    ActiveWindow.View.ShowHiddenText = False

    For Each oCtrl In ActiveDocument.InlineShapes
        If oCtrl.OLEFormat.ProgID = "Forms.CheckBox.1" Then
            Set oCheck = oCtrl.OLEFormat.Object
            If oCheck.value = False Then
                oCheck.Select
                Selection.Font.Hidden = True
            End If
        End If
    Next oCtrl
lbl_Exit:
    Set oTable = Nothing
    Set oRng = Nothing
    Set oCtrl = Nothing
    Set oCheck = Nothing
    Exit Sub
End Sub
__________________
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
  #5  
Old 12-16-2021, 01:27 PM
AVarg123 AVarg123 is offline Move table using VBA Windows 10 Move table using VBA Office 2016
Novice
Move table using VBA
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default

Graham, Table moved to the top but I have to run the macro manually. Attached is the document I am working. Table at the bottom of the page should be pasted below the heading, VISA Clearance Form when document opens. All unchecked checkboxes under "VISA Sponsorship Options" should be hidden when the document saves. Is that possible? Thanks again for all your help.
Attached Files
File Type: docm XX_VISA_Clearance Approved_12.14.21_Test.docm (77.4 KB, 11 views)
Reply With Quote
  #6  
Old 12-16-2021, 11:24 PM
gmayor's Avatar
gmayor gmayor is offline Move table using VBA Windows 10 Move table using VBA 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

To do at least some of what you require you need to save the document as a template (see attached) and create new documents from it, otherwise automating from a save event will make an unholy mess of the original.
When you first save the created document it will copy the table to the start as requested, leaving the original in situ.

Because of the way you have formatted the document, if you hide the check boxes, the general format of the document is lost as space changes to accommodate the hidden controls. This is a particular issue with the tables that has no simple answer.

If you really must have the various unchecked options hidden, I wouldn't have them in the document in the first place. I would instead employ a userform - Create a userform to make the selections and write the appropriate entries to content controls, but that would mean a complete redesign and a steep learning curve to create the form.

If that is too onerous, I would suggest not attempting to hide them. In addition to the formatting problems you will encounter, unless you submit the form as PDF, hidden texts are easily unhidden, which rather defeats the point of hiding them.
Attached Files
File Type: zip XX_VISA_Clearance Approved_12.14.21_Test-1.zip (51.9 KB, 13 views)
__________________
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
  #7  
Old 12-17-2021, 08:50 AM
AVarg123 AVarg123 is offline Move table using VBA Windows 10 Move table using VBA Office 2016
Novice
Move table using VBA
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default

I am opening this word document from a web application so .pdf is not applicable in this scenario. By the way, the link, 'Create a userform' is not working. Question, how can I move the table below the heading of the document in your Macro1 code? Thank you!
Reply With Quote
  #8  
Old 12-17-2021, 10:26 PM
gmayor's Avatar
gmayor gmayor is offline Move table using VBA Windows 10 Move table using VBA 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

The link works from here. Try accessing the page from my web site.
To put the table after the heading, as in the template attached to my previous post, change the line
Code:
 Set oRng = ActiveDocument.Range(0, 0)
which set the range at the top of the document to
Code:
Set oRng = oDoc.Paragraphs(2).Range
    oRng.Collapse 0
__________________
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
  #9  
Old 12-21-2021, 08:43 AM
AVarg123 AVarg123 is offline Move table using VBA Windows 10 Move table using VBA Office 2016
Novice
Move table using VBA
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default

Hi Graham, When I used the above code, I got "Object Required" error.
Reply With Quote
  #10  
Old 12-21-2021, 09:42 PM
gmayor's Avatar
gmayor gmayor is offline Move table using VBA Windows 10 Move table using VBA 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

Oops. Change oDoc to ActiveDocument
__________________
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
  #11  
Old 12-22-2021, 10:03 AM
AVarg123 AVarg123 is offline Move table using VBA Windows 10 Move table using VBA Office 2016
Novice
Move table using VBA
 
Join Date: Dec 2021
Posts: 15
AVarg123 is on a distinguished road
Default

Perfect! It worked! Thank you for all your help.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Move table using VBA Move entire rows from one table to another table Marcia Excel Programming 4 11-16-2021 05:24 PM
Change default move row behavior to "shift-move" JoshM Excel 2 10-05-2018 05:06 AM
Move table using VBA Move Selection to the next Column on a Page (Not a table) GuitarForLife Word VBA 7 02-09-2018 01:59 PM
Move table using VBA Move table cell contents from one table to another table or cell in same table donaldadams1951 Word VBA 4 02-04-2015 03:54 PM
Move table using VBA Move existing table captions bcarlier Word Tables 17 05-10-2014 02:36 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:32 PM.


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