Creating variables/automation in Microsoft Word - automation

I write a lot of proposals in MS Word and we use a template that we go in and change out specific values, i.e. Client Name (used multiple times throughout document), URL, Price, Page count, etc... Sometimes these variables get overlooked or missed. I wanted to know is there a way to just type the Client name once and have it update throughout the page. Also is it possible to edit these values in a separate document and link the proposal template to generate a modified proposal each time?
I'd like to know if all this is possible within just Word and not using VB scripts or anything like that.

Mail merge?
Or maybe a template/form would be better for you.

Related

Automating the process of creating doc word

I have a .doc template I use for building CVs for many friends.
I'm trying to automate this process using simple library/program, for exmaple, that can accept data like name, email, phone number, job title, and can create the .doc automatically.
What framework can be used for that to make it fastest i can?
Thanks,
Tal
Where exactly are keeping this template and are your friends plugging in the data or are you doing it all yourself?
No matter what, you're basically looking to do a data merge. An example of a data merge is a mail merge:
https://support.microsoft.com/en-us/help/294683/how-to-use-mail-merge-to-create-form-letters-in-word
The same thing really applies to what you're accomplishing to do.
You can take a template, specify the fields that require variable data (aka the different information that's changing), and then just use a spreadsheet to pull the data from and plug it in.
Now the question you'll probably be wondering next is how data merges use spreadsheets. The way data merges work is that each column you set with data in it, that should correspond to the changing lines in your template. I strongly recommend you read up on this further - it's not that difficult to do once you get the hang of it.
The last question is probably how you'll compile the data into this spreadsheet. Are your friends going to fill out an online form perhaps? If so, you'll need an online form of some sort perhaps, so you'll need to use some PHP, have a database to store the information from the form, and then just go to the table and export the information as a .csv file after you see you have enough data populated in your database table to do a data merge.
If you don't have access to MS Office, I'm sure you can accomplish this in OpenOffice.org instead (which is free/open-source).
Hope this helps.
At my job we do data merges all the time - for mail merges, for letters that need to be personally address to individual recipients, and we do this for people who need to print dozens of different business cards for different employees. We take their business card template and just do a data merge from a spreadsheet to save time on needing to set up individual files. P.S. you can also use Adobe inDesign for this, if you know how to use it.

inject static content word document while mail merge is running?

The rules available for mail merge in ms word 2007 appear to be limiting. I have created a mail merge to fetch about 10000 rows of data from excel and merge this data into word document by using a mail merge. This works as expected I have even used some conditional statements to display default text when a field is empty. However, I have been asked to insert a static page every 50th page which would include messaging not provided in excel file. When this static text appears on page 50, then 100, then 150 etc it would be static text and no other fields from merge would appear on page. In other words these fields would be replaced by static text. Is there an easy way to do this? I was thinking I could code something in vba and create a new page on the fly when a certain page number is reach ex. 50
Thoughts are much appreciated.
There is a lot of code on the Internet. Start with MSDN. If you google for "VBA MailMerge" you will also come across a number of links to threads in StackOverflow dealing with calling MailMerge from Excel. I suggest you focus on a method in which you imagine that you would like to work and research the code that might do the job. You will then arrive quickly at a stage where you actually might need the kind of help that is being offered here to abundantly.

VBA Word: How to separate content from formatting information?

I am trying to write a VBA-macro that converts a given MS word document into a sequential list of the document objects contained in that document (e.g., Paragraph, Table, etc.). For each of those objects I want to extract the text contained and its explicit formatting information to save it in a DB.
Would have any pointers for me how to get started? Are there any elegant solutions to this document parsing task?
Without knowing your full requirements this is just some suggestions.
You may be able to do what you want, but it will be a mammoth task to pull apart word documents and be able to stich them back together. If you di dwant to go with this approach, the best might be to pull out paragraphs, images etc and save these sections as individual documents in your database. They can then be put back together using
For i = 1 To ActiveDocument.Paragraphs.Count
MsgBox ActiveDocument.Paragraphs.Item(i)
Next i
ActiveDocument.Content.InsertAfter AnotherDocument
This is incredibly basic and will be a LOT of work to get working correctly.
I wonder would turning the documents into html be better (done simply by saving as HTML) and then you can use open source libraries to allow users to edit parts of the document. Eg add the jeditable plugin for jquery and almost any paragraph in your html word document becomes editable. A simple backend php script to save the changes and you have something that works. You can then also note what has changed for translation purposes.
They docs can be saved back as word docs or pdfs before being sent to the customer
Just an idea.

I need to store HTML emails in a database. Is that a bad idea?

The templates for these HTML emails are all the same, but there are just different variables for say, first name, last name and such.
Would it just make sense to store the most minimal of data that I need, and load the template in and replace the variables everytime?
Another option would be to actually create the HTML file and store a reference to it, which probably would be the easiest to do except it might be a pain managing the files, and it adds complexity in regards to migrating, file permissions, et cetera.
Looking for opinions from people who've done this before...
GOAL/PURPOSE/USE:
I have a booking engine. When users make a booking, they are sent a confirmation email, generated from the sessionized booking data.
This email provides a "Cannot view this email? See it here" link which provides a web view of the email, in addition to a plaintext view.
I need to display the same email that was sent out, in addition to the plaintext view.
The template is subject to change, but I think because of that very fact I should have a table of templates and map the data to a template.
That's what I would do, because the template layout may change over the time, but the person information should remain the same. So, it makes sense to just store the person information in the database and leave the template out from the database.
In fact, it would be even better if you use template engine such as Velocity (in Java) to construct your HTML emails... very easy, by the way.
On the one hand cpu is more expensive then memory, so mostly it is better to save more data to reduce cpu power used by computation.
But in your case, I would save the minimal data, the emails or what you are tying to save, because it allows you to easily remodel your templates, and to reuse the data at multiple places of your application.
You persist redundant data (especially because of the template) which is in no way normalized. I would not suggest to do that. But mentioned in the comment it is important what you want to do with that data.
If you only save the data you need you could for example exchange that template easy and use another one.
Yea, your right on track. I did a similar thing. All dynamic/runtime variables were starting from ##symbol.
So in database you would have one Template table. One table would be for dynamic/runtime variables. One table for Mapping between Template and dynamic/runtime variables.
tblTemplate - TemplateID, TemplateValue
tblRuntimeVariables - RuntimeVariableID, VariableString, VariableSQL
tblMapping - TemplateID, RuntimeVariableID, RuntimeVariableValue
Advantage of using an extra mapping table is that on adding new dynamic variables to existing change would mean making no change to existing database. Only more rows would be added to tblMapping.
In my case I was also having one extra column for storing SQL Statements in tblRuntimeVariables in case the value for a runtime variable is fetched from database.

SSRS 2005 - Looping Through Report Parameters

I would like to be able to loop through all of the defined parameters on my reports and build a display string of the parameter name and value. I'd then display the results on the report so the user knows which parameters were used for that specific execution. The only problem is that I cannot loop through the Parameters collection. There doesn't seem to be an indexer on the Parameters collection, nor does it seem to implement IEnumerable. Has anyone been able to accomplish this? I'm using SSRS 2005 and it must be implemented within the Report Code (i.e., no external assembly). Thanks!
Unfortunately, it looks like there's no simple way to do this.
See http://www.jameskovacs.com/blog/DiggingDeepIntoReportingServices.aspx for more info. If you look at the comments of that post, there are some ways to get around this, but they're not very elegant. The simplest solution will require you to have a list of the report parameters somewhere in your Report Code, which obviously violates the DRY principle, but if you want the simplest solution, you might just have to live with that.
You might want to rethink your constraint of no external assembly, as it looks to me that it would be much easier to do this with an external assembly. Or if your report isn't going to change much, you can create the list of parameter names and values manually.
If I'm understanding your question, just do what I do:
Drop a textbox on the report, then while you are setting up the report, insert the following:
="Parameter1: " + Parameters!Parameter.Label + ", Parameter2: " + Parameters!Parameter2.Label...
Granted, it's not the prettiest thing, but it does work pretty well in our app.
And I'm using Labels instead of Values since we have datetime values, and the user only cares about either the short date or the month and year (depending on circumstance), and I've already done that formatting work in setting up the parameters.
I can think of at least two ways to do this. The first might work, the second will definitely work.
Use the web service. I'm pretty sure I saw API for getting a collection of parameters. Even if there's no direct access you can always create a standard collection and copy the ReportParameter objects from one to the other in a foreach loop - and then access Count, with individual parameter properties available by dereferencing the ReportParameter instances.
Reports are RDL. RDL is XML. Create an XmlDocument and load the RDL file, then use the DOM to do, well, anything you like up to and including setting default values or even rewriting connection strings.
If your app won't have file-system access to the RDL files you can get them via the web service.