vb.net word automation - bookmarks - vb.net

I am preparing to make mechanism to fill out word template. I want to fill out it by data from my program. I heard about word bookmarks that I could create and then from program put the data to it. Unfortunately I heard also that when I want to put same value in different places in word I need to prepare separated new bookmarks for it. For instance I want surname to be in 3 different places in word then i cannot use one bookmark for it. Is it true? If so is there any other way to do it?

Yes, you can fill out bookmarks from your program. Be aware of the two different types of bookmarks which are called open or closed (one is empty, the other contains text and you can replace parts of the text or the whole text).
Yes, you can use a bookmark name only once. But you can manipulate the bookmarks in your program when you use bookmarks like bookmark_1 and bookmark_2, so you can replace the same content on different places. Helpful is the object model (https://msdn.microsoft.com/en-us/library/ff841749%28v=office.14%29.aspx)

Related

Is it possible to use variables in a PDF document?

I want to make a editable PDF document – but I want to take it a step further.
Is it possible to create some editable fields on the first page where the user can put in personal information (name, age etc.) and have the document fill itself in where "name" is required?
I need this for some employment contracts and it would be alot faster if the user only needs to fill the information in once, print the PDF and sign it. :)
In PDF a single form field may have multiple widgets. By definition all these widgets have the same content.
E.g. have a look at thie sample document aFieldTwice.pdf. You see two fields. As soon as you edit one of them and press enter, the same content occurs in the other one.
This might be what you look for.

Locking text fields in embedded document

I have been tasked with updating a spreadsheet that produces a report by replacing text in a template. Previously, the worksheet referenced an outside/separate file-- my job is to get it working in an embedded document.
I currently have text form fields for every input I want to insert within the embedded document template. As it stands, users can edit the document template however they like, but if they accidentally erase a text form field (again, where text is replaced via the vba macro) then it will break the macro and the spreadsheet will be useless.
My question:
Is there some way to lock or protect text form fields such that the rest of the document is editable? I essentially want to have the inverse of a "text form field only" protection.
Alternatively, is there a better way to approach this project? I'm thinking of leaving the spreadsheet as is, but including a "reset" button bringing the template back to it's original state if anything breaks. If I did this method, this would require there NOT to be an external file. Attempts to do this so far have proven unsuccessful.
My general methodology/algorithm goes as follows:
Open the reference document
Replace all the text form fields via bookmarks with plain text,
making sure to reassign the bookmarks afterward (so as to not lose
them if they run the macro more than once).
Save the embedded document as a .doc with the inputs inserted
Replace all bookmarked inputs with text form fields to return the
template to its original state
Any information would be IMMENSELY appreciated. I am slowly running out of time and am feeling stuck.
Many thanks!
-Sooji

Word 2010 - Force Formatting In Specific Parts of Document

I am working with Microsoft Word 2010. I have a document that serves as a template for multiple users for a project I am working on. There are two parts of the document I want to force formatting when a user types:
Enter in an email address - I want the address to not automatically turn to a hyperlink. I want it to not turn to a hyperlink on just this part of the document. The rest of it I want hyperlinks to be enabled.
Enter in a URL without www in front (i.e. google.com), and not have the first letter automatically capitalize. I don't want to turn off capitalizing the first letter of a sentence in the whole document. Just in this part of the document.
Is this something that can be done? I tried messing with Fields but did not have any luck. I am familiar with VBA so if there is a way to do this with code, I am open to that too.
Both features you requires are implemented in Word using AutoCorrect/AutoFormat. They are not controlled by the style mechanism and consequently can't be selectively activated.
The mail address formatting can be controlled by styles, and you could prevent the switch to the Hyperlink style from being visible. You could also consider a macro that selectively changes the styles of the text as required in a post-processing pass through the documents - perhaps the next time the document is opened by a user for review.

Add bookmarks and cross references to a Word document

In Word 2010 I want to add text to a document, bookmark this text and then cross reference this text in the header and footer of the document.
Can this be recorded or will I have to code it?
Yes it is possible.
Yes you can record in Word - allthough with some limitations as you can't navigate thru your text by mouse when in recording mode; the generated code will be ugly and full of "hard coding" but will give you an impression which objects, methods and properties might be relevant..
If you want a solution that is a bit more sustainable than a one-off, proper coding surely is the way to go. You should make friends with the following in order to solve your task:
the Selection object and its methods, especially GoTo, Move and its variants
the way to extend a cursor to mark text
inserting text using various Insert... methods (e.g. Selection.InsertCrossReference ReferenceType:="Bookmark" ...)
adding bookmarks to the Bookmarks collection
understanding how to manipulate headers & footers
Try some coding and come back with more sopecific questions if you get stuck.

Transferring Rich Text data from Access to Word

I've been saddled with supporting an old Access 2003 database (with SQL backend) produced by a now out-of-business contractor.
The database includes several 'unconventional' reports. They all use Automation through VBA to output fields directly to a Word document. Kind of like this (pseudo code):
for each row{
output(row.id);
moveRight();
output(row.firstName);
newLine();
}
Etc.
The problem is, the database includes several rich text fields. To output these (including their formatting) to the document, the developer opens a separate Access form, with a single rich text control, and pulls the appropriate field into the text box.
He then does a 'select all, copy', flicks back to Word, and then pastes the text.
My task is to add a new rich text field to a report, and I feel there must be a better way of doing this...
Ah! A duplicate question apparently.
Here's the answer:
Word Automation: Write RTF text without going through clipboard