![]() |
#1
|
|||
|
|||
![]()
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!
|
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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.
|
#4
|
||||
|
||||
![]()
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 |
#5
|
|||
|
|||
![]()
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.
|
#6
|
||||
|
||||
![]()
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.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
![]()
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!
|
#8
|
||||
|
||||
![]()
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) 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 |
#9
|
|||
|
|||
![]()
Hi Graham, When I used the above code, I got "Object Required" error.
|
#10
|
||||
|
||||
![]()
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 |
#11
|
|||
|
|||
![]()
Perfect! It worked! Thank you for all your help.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |
![]() |
GuitarForLife | Word VBA | 7 | 02-09-2018 01:59 PM |
![]() |
donaldadams1951 | Word VBA | 4 | 02-04-2015 03:54 PM |
![]() |
bcarlier | Word Tables | 17 | 05-10-2014 02:36 PM |