Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2023, 11:00 PM
nathananaru nathananaru is offline How can I write VBA code to 'reset' a word document to a former state? Windows 10 How can I write VBA code to 'reset' a word document to a former state? Office 2021
Novice
How can I write VBA code to 'reset' a word document to a former state?
 
Join Date: Nov 2023
Posts: 3
nathananaru is on a distinguished road
Post 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!
Reply With Quote
  #2  
Old 11-03-2023, 04:15 PM
Guessed's Avatar
Guessed Guessed is offline How can I write VBA code to 'reset' a word document to a former state? Windows 10 How can I write VBA code to 'reset' a word document to a former state? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 11-05-2023, 02:57 AM
vivka vivka is offline How can I write VBA code to 'reset' a word document to a former state? Windows 7 64bit How can I write VBA code to 'reset' a word document to a former state? Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Thumbs up

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!
Reply With Quote
  #4  
Old 11-05-2023, 07:35 PM
Guessed's Avatar
Guessed Guessed is offline How can I write VBA code to 'reset' a word document to a former state? Windows 10 How can I write VBA code to 'reset' a word document to a former state? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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

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
How can I write VBA code to 'reset' a word document to a former state? 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
How can I write VBA code to 'reset' a word document to a former state? Reset Word Document gaafar.dafalla@illinois.g Word 1 12-01-2015 04:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:54 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