![]() |
|
|
|
#1
|
|||
|
|||
|
I found this old post/macro Here, but it both gives an error and not sure if will do what I'm trying.
Is there any way to do a global search and replace of text to a Field Code? I have about 70+ tables in Word that are OLE links to an excel file. An example of one looks like below Code:
{ LINK Excel.SheetMacroEnabled.12 "C:\\Data\\Test WPS with Exam Highlights.xlsm" "Cover Charts!Charts_Cover_Main" \p }
Code:
{LINK Excel.SheetMacroEnabled.12 "{DOCPROPERTY WPFilePath}{DOCPROPERTY WPFileName}" "Cover Charts!Charts_Cover_Main" \p }
Last edited by ptmuldoon; 01-03-2015 at 08:45 AM. |
|
#2
|
|||
|
|||
|
There's no way to put a field construction into the Replace With box of the Replace dialog, but there is a way to do what you want.
Somewhere in the document (or in another document in Word), insert the two fields {DOCPROPERTY WPFilePath}{DOCPROPERTY WPFileName} and then cut them to the clipboard. Make sure that field codes are visible in your document (press Alt+F9 if needed). Open the Replace dialog and type the existing path & filename (without the quote marks) in the Find What box. In the Replace With box, enter the code ^c which represents the clipboard contents. Then click Replace All. For future reference if you don't remember the ^c code: Open the Replace dialog, click in the Replace With box, click the More button, and then click the Special button at the bottom. In the popup menu, click the "Clipboard Contents" item to insert the corresponding code in the Replace With box. |
|
#3
|
|||
|
|||
|
Thanks
I was just about to post back as well when I found your answer. From some code from Macropod, and testing recording a macro, I learned to do a search and select the text to replace it like this as well. Code:
Sub FindMyWords()
Application.ScreenUpdating = False
Dim strWords As String, i, j As Integer
strWords = "C:\\Data\\"
j = 0
With ActiveDocument.Content
With .Find
.Text = strWords
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
j = j + 1
.Select
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCPROPERTY WPFilePath ", PreserveFormatting:=True
.Find.Execute
Loop
End With
MsgBox j & " instances found."
Application.ScreenUpdating = True
End Sub
I did find that if you update the OLE links, you do lose the Field Code as it gets converted to the value. But that is ok, I was looking to change them all so that I can then save the entire OLE link with the fieldcode as a building block. |
|
#4
|
||||
|
||||
|
You should note that, contrary to your example of what you say you want to do, it is not possible to embed any kind of filed in a LINK field. If you do so, the embedded field will be converted to its result the first time it updates.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to hide field codes from others?
|
lucky16 | Word VBA | 2 | 10-24-2014 03:52 AM |
| VBA script to update field codes? | Calab | Word VBA | 1 | 04-07-2014 09:27 PM |
| Formula Field using Field Codes | hunter2193 | Word | 3 | 04-05-2013 04:58 AM |
Word Equation field codes
|
mkarthic | Word | 1 | 12-02-2011 02:09 AM |
confusion with merge and field codes
|
BluRay | Mail Merge | 5 | 03-29-2011 01:06 AM |