#1
|
|||
|
|||
How can I write VBA code to 'reset' a word document to a former state?
Hello everyone,
I am new to VBA and I have a problem I am trying to solve I have a form which has sections that need to be constantly replaced and then reset. An example of this would be: "this [item] is [colour] and weighs [weight]" which would become "this house is blue and weighs 1g" How do I make a function which will revert "this house is blue and weighs 1g" back to "this [item] is [colour] and weighs [weight]" ? Hope that makes sense, any help is much appreciated! |
#2
|
||||
|
||||
The three fields should be plain text content controls. If you do this and then type in to each the text that you want as the default (empty) prompts you can then run the first macro to set the default text values.
Once the placeholder text is configured, you don't need to run that macro again. Then you can run the second macro to reset back to default. Code:
Sub SetupCCs() Dim aCC As ContentControl For Each aCC In ActiveDocument.Range.ContentControls aCC.SetPlaceholderText Range:=aCC.Range Next aCC End Sub Sub ClearCCs() Dim aCC As ContentControl For Each aCC In ActiveDocument.Range.ContentControls aCC.Range.Text = "" Next aCC End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Andrew, although this was not my question, I want to thank you for the answer! I've never known about content controls and their usefulness! You gave me a good push into learning them. Thanks!
|
#4
|
||||
|
||||
Good to hear, Vivka.
If you do a search on this forum you will find lots of threads that explore some of the facets of Content Controls which will give you a good understanding of how they can be used. I often point people at the template tools for Content Controls made available by Word gurus Greg Maxey and Graham Mayor. Either one of those tools is also worth downloading to help in your exploration.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
help a novice, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to write or change text inside a rectangle in word document | tech21 | Word | 5 | 01-17-2023 12:39 PM |
Reset Word Document Bookmark Values | hkrawick@gmail.com | Word VBA | 5 | 07-29-2022 05:48 PM |
How to write a macro to count the number of lines between the start of a Word document to where the | soroush.kalantari | Word VBA | 3 | 08-08-2021 09:23 PM |
Word document with VBA and Form Fields reset when select File,Print | fatal.lordes | Word VBA | 9 | 04-27-2018 11:30 PM |
Reset Word Document | gaafar.dafalla@illinois.g | Word | 1 | 12-01-2015 04:39 PM |