Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-27-2016, 09:56 AM
dwirony dwirony is offline How to Dim a substring between two strings Windows 7 64bit How to Dim a substring between two strings Office 2003
Advanced Beginner
How to Dim a substring between two strings
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default How to Dim a substring between two strings


Hello all,

I am trying to Dim some text as a variable for another macro of mine. For example, the value I want to Dim is located between the words "to host the" and "group at the location". Once I have the variable, I want to use it to fill in other paragraphs throughout my document, something like this -

Code:
With Selection.Find
        .Text = "The event is to be held with the designated group at the location"
        .Replacement.Text = "The event is to be held with the " & Dim VARIABLE & " group at the location"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
Any solutions to how I could go about this?
Reply With Quote
  #2  
Old 10-27-2016, 02:52 PM
Guessed's Avatar
Guessed Guessed is offline How to Dim a substring between two strings Windows 10 How to Dim a substring between two strings Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Your terminology is not good. You are actually trying to replace a word in a range with a field/content control/bookmark.

When you say you want to use this 'variable' to fill in other paragraphs - does this mean you want just the value of this variable (ie 'designated') to be replicated in other locations or that the value of this variable causes other text to change based on other parameters?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-27-2016, 03:00 PM
dwirony dwirony is offline How to Dim a substring between two strings Windows 7 64bit How to Dim a substring between two strings Office 2003
Advanced Beginner
How to Dim a substring between two strings
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default

You're right, I poorly misconstructed what I'm looking for. I am trying to give the variable a value so that I can place it in new paragraphs that I'm generating that have "xxxx" within them (where I want that variable to be). I'm trying to replace the xxxx with the variable instead of just manually copying and pasting it from the original paragraph. Is that clearer?

So if the word I want is "either "Florida" or "California", and it always generates in between two words (Let's just say "of" and "State", but both are unique to the document), I want to then have my macro take whichever state it is and replace "xxxx"throughout my document with it.
Reply With Quote
  #4  
Old 10-27-2016, 03:12 PM
Guessed's Avatar
Guessed Guessed is offline How to Dim a substring between two strings Windows 10 How to Dim a substring between two strings Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

OK, so I would do this by using a Content Control linked to a document property. This is easiest to do by using one of the 'built-in' metadata fields by going to Insert > Quick Parts > Document Property (and choosing one, say 'Company'). This can then be copied to other locations (or inserted the same way) to get a result where editing any one of these results in the others automatically updating.

If you need this happening via vba you can copy that range to the clipboard ie "The event is to be held with the ContentControl group at the location" and then include the contents of the clipboard in your VBA code eg
Code:
With Selection.Find
        .Text = "The event is to be held with the designated group at the location"
        .Replacement.Text = "^c"
        .Execute Replace:=wdReplaceAll
    End With
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 10-28-2016, 07:51 AM
dwirony dwirony is offline How to Dim a substring between two strings Windows 7 64bit How to Dim a substring between two strings Office 2003
Advanced Beginner
How to Dim a substring between two strings
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default

Hm, this might not be a viable solution for me, unless I'm reading this wrong. Here's another scenario I have - A company name always generates in the first paragraph between the words "The company " and " shall be responsible for". I want to be able to, using vba, take that company name and replace every "XXXXXX" throughout my document. Without using one of the built-in options, is there a way I could put this into code, knowing the place the company name always generates is unique?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to substring and trim in excel Mahesh G Excel 0 08-16-2016 06:03 AM
Substring to return numbers funkyfido Excel 4 07-22-2016 10:03 AM
How to Dim a substring between two strings How to link similar strings. PRA007 Word VBA 2 01-20-2016 04:22 AM
How to Dim a substring between two strings Search with multiple strings silverspr Excel 7 03-03-2013 04:45 PM
How to Dim a substring between two strings update style of all strings available between two specific strings vikrantkale Word 1 03-28-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:37 PM.


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