Obtaining the Total Number of Bookmarks Within a Word Document - ms-word

I am working on word page in Microsoft Office 2013, and I'm adding bookmarks to my page, I need to get a total count of how many bookmarks are on my page.
What method can be used to obtain the total number of bookmarks within the document?

You can do this in vba.
Open the VBE by simultaneously pressing AltF11. Enter this into a module, then run the code:
Sub countBookmarks()
MsgBox Bookmarks.Count
End Sub
This will bring up a MsgBox telling you the number of bookmarks you have.
If you so desire, you can assign this routine to a shortcut key to automatically run the code with the press of a couple of buttons.
Or you can just type AltF8 to bring up the list of macros you have stored in your document, which you can also run from there.

The code in the response marked as "The Answer" will not run in Word - it causes an error message.
Generally, to count the bookmarks in the main body of the currently active document, use:
Sub CountDocumentBookmarksInDocument()
MsgBox ActiveDocument.Bookmarks.Count
End Sub
If, as is also stated in the original question, you want to count the bookmarks on the current page:
Sub CountBookmarksOnPage()
ActiveDocument.Bookmarks("\page").Select
MsgBox Selection.Bookmarks.Count
End Sub

Related

Visual Studio Code select same position above and below not the whole line before and after (see image)

I'm using visual studio code and run into a weird problem. I'm not sure how I got here - I could have accidently pressed a shortcut unknowingly.
I'm trying to select a phrase, link or anything that crosses multiple lines (whether the lines are true lines or due to word wrap). When I select multiple lines, it doesn't automatically select the text at the start and end between the two points. Rather, it just selects the length of text for that line and repeats it in the subsequent lines. See the image below to understand.
Image of issue
As you can see, I am trying to select the words from "the" to the end of "sub". Instead of selecting all the words between the two, it selects the text "the instru" and selects every line with the same amount of characters/length.
In order to show what I am expecting, I have pasted the text into Notepad and done the same thing.
What I am expecting
As you can see, all the words between "the" and "sub" are selected.
If anyone has any idea about how to fix this, I would be greatly appreciative.
Below is a copy of the text if the images don't display.
Follow the instructions below for a click guide to retire and/or add 'School'.
Best practice if there is a change in 'School' structure would be to 'retire' any existing school setup that is no longer required and add the new sub school information. The reason why we don't just edit existing school names (typically) is due to leaving historical data intact.
Try using ctrl+shift+P and typing "Toggle Column Selection Mode"

How to populate fields/form in word document from other word document?

I have a Word document that has fields where information is populated by the user manually. There are couple of other documents with same fields and the user would like to populate those automatically, based on information in first document. How to achieve that? Documents are in .doc format.
I've tried looking around before coming here, but every site I've managed to find (that has title of "Filling fill-in forms in Word" and similar) actually describes how to prepare a document for such action, not how to insert the data in from other document. I'm maybe missing something very obvious, but can't figure it out.
All documents have "Allow only this type of editing in the document:" ticket and "Filling in forms" selected under "2. Editing restrictions" in Restrict Editing menu.
This is a borderline question, as it technically falls in the end-user area. But it could also be an interesting question for developers as there is no direct way to achieve what is required using the object model, except by following the steps below (i.e. inserting IncludeText fields).
In the source document, it's necessary to use content controls for text input (form field dropdowns work fine) and bookmark them. The content of a legacy form field textbox will not come through.
In Word, in the target document, go to Insert->Object->Text from file
in the dialog box click the Range button, type in the bookmark name
select the option to "Insert as Link"
This creates an IncludeText field in the document that references the file path to the source document and the bookmark content:
{ INCLUDETEXT "C:\\Test\\TestFormsProtection.docx" Text1 }
Note that there is no reliable (sometimes it might work, but other times not) way to use relative file paths with Word field codes.
The relevant VBA code to generate this field at the end of the active document:
Dim doc as Word.Document
Dim rng as Word.Range
Set doc = ActiveDocument
Set rng = rng.Content
rng.Collapse wdCollapseEnd
doc.Fields.Add rng, , "IncludeText " & Chr(34) & "C:\\Test\\TestFormsProtection.docx" & Chr(34) _
& " Text2", false

Microsoft Word restart page numbering

In MS Word for Windows 10, if you wish to restart page numbering from "1" in the middle of a large document, doing so is currently a 7 step process. For example, let's say you have a document with 4 sections and on each section you wanted to restart the page numbering from "1".
I had two related questions:
Is there a way that, not involving adding any code to the source material, that a user can restart page numbering with 1 or 2 steps as opposed to 7?
If no, did anybody have a script that would allow the functionality described above?
Thanks
You can set the page numbers to restart by right-clicking on the page number, selecting Format Page Numbers... from the context menu and then, in the dialog now opening, entering the desired start value. Seems easy enough to me actually.
If you want to make it simpler you can add the below macro to your Normal.dotm file. You can then add a button to your Quick Access Toolbar that you bind to the macro and the command will be a single click away.
Note that page numbering always works per section, so your document will already have to contain the respective sections.
Sub RestartPageNumbers()
Dim startingNumber As Integer
startingNumber = InputBox("Start page number at: ", "Restart Page Numbers", 1)
ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter
With Selection.HeaderFooter.PageNumbers
.RestartNumberingAtSection = True
.startingNumber = startingNumber
End With
ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument
End Sub

IDA - Searching for a pushed value

How do I search for a pushed value in IDA?
I have a value that is pushed into a certain function.
I want to search for it like:
push 420
How do I that?
Make sure you have closed all remaining search result windows. Such windows are titled with "Occurences of: ...". This is necessary to get the right window.
Hit "Alt+t" to open a new text search window.
In the search field, enter 'push 420' without the '.
NB: You have to get the number of spaces right. I got them like this: I searched for "push" only at first. Then I right clicked on the result, copied it and inserted it into my new search. This gives you the right number of spaces.
Make sure you have selected "Find all occurences". Make sure you have not selected any Parameters (e.g. "Regular expression", ...)
Hit OK

Word 2007 password protection for single words

is it possible to put a password on a single word inside a word document?
What I want is to write a system documentation from our IT structure. I want to put the passwords in the document as well. Now I want that you have to enter a "MASTER" password in order to unlock to passwords inside the document. If you do not enter the password, the passwords inside the document should be invisible or something like that.
Is that possible?
Yes, this is possible. To make this work we have to use a combination of Word's inherent document protection, its hidden text attribute, and a couple of VBA tricks.
First, format all the passwords in the document as hidden text. (For those who are unfamiliar, hidden text is only visible when the Show/Hide function is set to true.)
Then add code to make sure that the hidden text will not display and also to protect the document from being edited whenever the document is opened:
Private Sub Document_Open()
AddProtection
End Sub
Sub AddProtection()
With ActiveDocument
.ActiveWindow.View.ShowAll = False
.ActiveWindow.View.ShowHiddenText = False
.Application.Options.PrintHiddenText = False
.Protect Type:=wdAllowOnlyReading, NoReset:=True, Password:="DesiredPassword"
End With
End Sub
Because Word users can normally display hidden text at any given time, we also need to take control of this function. Most menu and Ribbon commands can be intercepted by creating a module containing subroutines named for the intercepted commands. Naming a Sub ShowAll will allow us to control this function and only display hidden text when a password is entered:
Sub ShowAll()
If ActiveDocument.ProtectionType = wdAllowOnlyReading Then
'Do nothing
Else 'restore the Ribbon's toggle function
If ActiveDocument.ActiveWindow.View.ShowAll = True Then
ActiveDocument.ActiveWindow.View.ShowAll = False
Else
ActiveDocument.ActiveWindow.View.ShowAll = True
End If
End If
End Sub
Finally, we add some code to prompt the user for a password and, if entered correctly, display the text that was formerly hidden:
Sub RemoveProtection()
Dim strPassword As String
strPassword = InputBox("Enter document password.")
ActiveDocument.Unprotect Password:=strPassword
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.ActiveWindow.View.ShowHiddenText = True
End If
End Sub
Once all the VBA code is entered, right-click on the module in the IDE, select Project Properties, and assign a separate password on the Protection tab. This will stop power users from getting to the embedded password or changing the code.
All that's left to do is create a QAT button in Word (that is only visible for this document) and assign the RemoveProtection sub to it. Whenever the document is opened the passwords will be hidden and protected from editing, but can then be revealed by clicking on the QAT button and entering the correct password.
EDIT
When I first answered this question, I failed to consider that Word has a hidden text option that can be turned on separateley from the Show All option. Additionally, hidden text can be printed via a printing option. I have added code in AddProtection above to turn off these settings.
Further testing also revealed that a user in Word 2007 could manually go into Office Orb|Options|Display to reveal the hidden text by changing the Show all formatting marks or Hidden text options manually. To avoid this, a Ribbon customization would need to be created and loaded with the document.
Finally, it is worth noting that although it is great fun to bend Word to one's will in order to make it accomplish tasks like this, the level of protection is not as good as encrypting the passwords separately and then unecrypting before revealing the contents or even using Word's document password feature to encrypt the document's entire contents.