#1
|
|||
|
|||
Visual basic Word Script To Remove Specific Areas of a Word Doc
I am trying to create a template in word that has a macro in it. With the macro I want to go through a series of questions, I want some of those questions to be answered as strings, some interger and some to be checkboxes. Then those will go through if statements to input or take away things from inside the word doc that opened from the template.
For example: IF (Integer that is answered in one of the questions) > 5 THEN (Code to input a certain text) I have no experience with Visual Basic, but experience with other programming languages. So just some examples would be very useful. I just mainly need to know how to input and delete text from word using a Visual Basic macro. Thanks, Dylan. |
#2
|
||||
|
||||
Depending on what you're trying to achieve, you may be able to get the desired results using formfields and formula fields, without the need for any macros/VBA. See, for example:
https://www.msofficeforums.com/word/...html#post46429 https://www.msofficeforums.com/word/...html#post74823
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I am trying to make a statement of work get prefilled by selecting different options. As every customer has different specifications, if I wanted x, I could select x and it would add a section that I have a written a bunch of text for. I was thinking of using if functions. For example, if x = 1 then insert "Text".
Is this achievable with formfields? I use fields already in my documents to allow for us to have the same customer name throughout the document, but these would be big chunks of text and titles. |
#4
|
||||
|
||||
You might at least look at the documents in the links I posted...
The conditional outout can include multiple paragraphs, tables and images.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I have had a look and it looks very locked down. Is it possible to be able to also edit it by hand with formfields? As if I am to do it with formfields I will need it to not be locked down because they will need to input text into fields to bring it down to other sections...
|
#6
|
||||
|
||||
Those demos are only 'locked down' in the sense they have formfield protection applied, which is necessary for the fields to work. You can, of course, create a far more complex document using such field coding and whatever other content, including formfields, that you might need.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
So, using formfields, would I be able to input sections and such? As, obviously I can unprotect it, edit it by hand then reprotect it?
|
#8
|
||||
|
||||
The conditional output can already include multiple paragraphs, tables and images, so why would you want to unprotect/reprotect the document?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Also, would you be able to give me an example on how to code adding text and sections with form fields? I think you are correct that I should be using this and I have figured out how it will fit into the document. I just need to figure out how to code it!
|
#10
|
|||
|
|||
It was me being silly. It is okay, I should not need to unprotect, I am going to keep a plain text document for when I need to write it by hand rather then unprotecting.
|
Tags |
macro in word, visual basic |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Visual basic code for Word 2003 template | KateAus | Word VBA | 4 | 09-09-2012 08:40 PM |
Word Visual Basic error - run time error 504 | crazymorton | Word | 11 | 01-13-2012 04:32 AM |
Visual Basic Editor changes from 2003 to 2007 | Rockitman31 | Word VBA | 4 | 09-21-2011 12:01 PM |
Word Basic 2003 to Word Basic 2007 Incompatibility | Mark1110 | Word VBA | 1 | 12-29-2010 11:04 PM |
A little Visual Basic Help Please | leroytrolley | Excel | 4 | 08-22-2008 03:57 AM |