How to assign paragraph / character styles automatically in word 2010 - vba

Hi I've a 200 pg fully formatted word document. The person who had worked on it earlier had not applied any style to the whole document and he has done it manually. Though the formatting was done very neatly it has become my job to assign character/paragraph styles to each and every paragraph. Does any one know of a script which assigns character/paragraph styles automatically to the existing word 2010 document?

You'd better use Word VBA to deal with your issue.
What you should do is:
Find the style you want to replace with a style (see MSDN or some tips)
Apply style to the found selection (see this SO thread: How do I apply a style to multiple selections in Word using VBA?)
If you want to check the right style, you can record a macro and adapt it.

You can use the Find and Replace dialog to find text based on its format (e.g. Bold, Size 14) and replace it with a Style (e.g. Heading 2).
This article sums it up pretty well....
http://www.howtogeek.com/howto/microsoft-office/search-and-replace-specific-formatting-fonts-stylesetc-in-microsoft-word/

Related

Unable to extract and re-insert MS Word Content Control using VBA and InsertXML

This question is related to my other question: Range.InsertXML using Transform
In MS Word it is easy to insert a content control using VBA, for example:
ThisDocument.ContentControls.Add wdContentControlRichText, Selection.Range
I've recently started exploring more in the XML side of things, e.g.:
Debug.Print ThisDocument.Range.XML seems to (or actually does) produce the XML for a Word document. However, if I create a NEW, BLANK document and add a Content Control I am unable to extract and reinsert the Content Control (oCC).
My steps:
added 2 blank paragraphs to a new document
added oCC to the 2nd paragraph
selected the oCC paragraph
immediate window: thisdocument.Paragraphs(1).Range.InsertXML selection.Range.XML
At first glance it LOOKS like the Content Control was duplicated, BUT on closer inspection, it was deleted and only the formatted text remains (see image, top paragraph is actually just formatted text).
Thinking I could out smart MS Word I set the properties of the Content Control to '...can not be deleted', but that didn't help.
I've also tried to insert into a separate document in case the issue had something to do with duplication of something that ought to have been unique.
In a nutshell:
To answer this question I need a way to insert a Content Control to a document using a combination of VBA and XML (or confirmation that what I am attempting is not possible).
Just realized I should use Selection.Range.WordOpenXML instead of Selection.Range.XML

Word - Conditional Text

I'm having to convert some documents which had been built in OpenOffice over to word, and one thing which seems overly complicated in Word is conditional text. OO had some features which made this a breeze, but I'm thinking I'm missing something in Word.
For more simple pieces of text I've used the {IF {DOCVARIABLE xxxx} = ...} method which seems to work well with single lines of text.
For longer blocks of text I've tried using a similar method but inserting an Autotext block. This works well if the content is static, but if the content I'm inserting needs to be edited, updating the document ends up replacing any changes with the Autotext block. So this method won't work for parts of my document.
Most of the search results I'm seeing use some variation of the two methods above. Is there something else I can use which allows blocks of text, possibly including tables, to be conditionally inserted or hidden and also editable?
Macros are okay since this is how I'm setting various DOCVARIABLE parameters in the document.
I'm using Word 2016 on Windows 7.
After doing more experimenting, it looks like I can use bookmarks to do what I need.
I can select the block of text I want to conditionally show/hide, then create a bookmark for the selection.
Then in my macro I can hide the section when necessary with:
ActiveDocument.Bookmarks("MyBookmarkName").Range.Font.Hidden = True
or show it again using False instead of True. This seems to hide tables and other things within that block of text. I'd love it if the Word developers would add some of the features for this type of thing which are in OpenOffice.

Can I create automatic headings in a Microsoft Word document which has around 500 pages?

I need to add headings automatically in a Word document which has 500 pages. All the topics written with the font 'Courier' and Size '24' needs to be given style - 'Heading 1'. Can someone help me write this using VBA?
Do you have to do this using VBA?
The Advanced Find function let's you highlight all text in your document based on parameters like font and size.
Set these parameters using the "Format"-dropdown -> "Font..."
Then use the "Find In"-dropdown -> "Main Document" to select all text matching your criteria.
See attached screenshot, and then manually set the style for the entire highlighted selection.

Microsoft Word MacroButton - placeholder text visibility

I have a Microsoft Office 2013 Word template, in which I have some text-field elements, created by using Quick Parts -> Field -> MACROBUTTON noname [Type your text here].
If I fill only some of these fields (i.e. "[Name]", "[Address]") and I print or save as PDF, all the fields that I have not filled will display as [Insert your text here] in the printed paper or PDF. To be clear, the placeholder text must be manually removed (or replaced with the text you want).
I've readed somewhere, that you can create a macro, which will not display the placeholder text in the PFD- or printed version of the document, if there is no text written manually to that specific field (you leave it as it was). As this would be handy in cases, where you don't fill all the neccessery fields, my question is:
Q: Can this be achieved only by using Macro Button, and if not, what is needed to create text fields as described below that are not included in the printed or PDF saved version of the document?
This cannot be achieved without using actual macro code. Right now your solution contains no macro code, the fields simply function as "targets" and when the user types on the field it is deleted. Where the user does not type, the prompt remains. You'd need code to delete these fields from the document.
Given your requirement, the code would have to fire in the DocumentBeforeSave and the DocumentBeforePrint events. These events require a class and supporting code in a standard module. The basic information on how to set these up is in the Word object model language reference: https://msdn.microsoft.com/en-us/library/office/ff821218.aspx
An alternative to MacroButton fields would be to use ContentControls. But here, again, code and the same events would be required to remove/hide placeholder text.

Update a field in Word 2013 using VBA

I created a word document where I use fields (with Document properties) in the text, in the Footers but I also created an Word Art object with the Title-field in it.
I can Update the fields in the document using:
ActiveDocument.Fields.Update
For the Footers I use the PrintPreview
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
But none of those updates my Field in the Word Art Object.
How can I update this?
A wordart object is a shape, is it really the case, that a word art object can contain a field instead of just overlaying? Can you put out some more information/ did you double check if the field may have been updated but the content stays the same?
I have found a suitable work arround in Word for my problem.
It is not realy neccesary to use Word Art, I can use the same with "Text Effects and Typography"
I am still curious if there is a real solotion for this, but for now it works dor me