Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2017, 10:19 PM
mackied mackied is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 10 Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2016
Novice
Visual basic Word Script To Remove Specific Areas of a Word Doc
 
Join Date: Jul 2017
Posts: 6
mackied is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 07-27-2017, 10:25 PM
macropod's Avatar
macropod macropod is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 7 64bit Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-27-2017, 10:46 PM
mackied mackied is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 10 Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2016
Novice
Visual basic Word Script To Remove Specific Areas of a Word Doc
 
Join Date: Jul 2017
Posts: 6
mackied is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-27-2017, 10:52 PM
macropod's Avatar
macropod macropod is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 7 64bit Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 07-27-2017, 11:00 PM
mackied mackied is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 10 Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2016
Novice
Visual basic Word Script To Remove Specific Areas of a Word Doc
 
Join Date: Jul 2017
Posts: 6
mackied is on a distinguished road
Default

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...
Reply With Quote
  #6  
Old 07-30-2017, 02:46 PM
macropod's Avatar
macropod macropod is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 7 64bit Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 07-30-2017, 02:57 PM
mackied mackied is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 10 Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2016
Novice
Visual basic Word Script To Remove Specific Areas of a Word Doc
 
Join Date: Jul 2017
Posts: 6
mackied is on a distinguished road
Default

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?
Reply With Quote
  #8  
Old 07-30-2017, 03:01 PM
macropod's Avatar
macropod macropod is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 7 64bit Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #9  
Old 07-30-2017, 03:09 PM
mackied mackied is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 10 Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2016
Novice
Visual basic Word Script To Remove Specific Areas of a Word Doc
 
Join Date: Jul 2017
Posts: 6
mackied is on a distinguished road
Default

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!
Reply With Quote
  #10  
Old 07-30-2017, 03:10 PM
mackied mackied is offline Visual basic Word Script To Remove Specific Areas of a Word Doc Windows 10 Visual basic Word Script To Remove Specific Areas of a Word Doc Office 2016
Novice
Visual basic Word Script To Remove Specific Areas of a Word Doc
 
Join Date: Jul 2017
Posts: 6
mackied is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
macro in word, visual basic



Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual basic Word Script To Remove Specific Areas of a Word Doc 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
Visual basic Word Script To Remove Specific Areas of a Word Doc Word Basic 2003 to Word Basic 2007 Incompatibility Mark1110 Word VBA 1 12-29-2010 11:04 PM
Visual basic Word Script To Remove Specific Areas of a Word Doc A little Visual Basic Help Please leroytrolley Excel 4 08-22-2008 03:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:36 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft