Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-03-2015, 07:36 AM
ptmuldoon ptmuldoon is offline Copying Raw Field Codes Windows 7 64bit Copying Raw Field Codes Office 2013
Advanced Beginner
Copying Raw Field Codes
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default Copying Raw Field Codes

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 }
and I want to replace both the File Path and File Name with Field Codes like below
Code:
{LINK Excel.SheetMacroEnabled.12 "{DOCPROPERTY  WPFilePath}{DOCPROPERTY  WPFileName}" "Cover Charts!Charts_Cover_Main" \p }
I tried using chr(19) and chr(21) in a replace, but still no luck yet.

Last edited by ptmuldoon; 01-03-2015 at 08:45 AM.
Reply With Quote
  #2  
Old 01-03-2015, 01:13 PM
jjfreedman jjfreedman is offline Copying Raw Field Codes Windows 7 64bit Copying Raw Field Codes Office 2010 32bit
Advanced Beginner
 
Join Date: May 2012
Location: https://jay-freedman.info
Posts: 39
jjfreedman is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 01-03-2015, 01:21 PM
ptmuldoon ptmuldoon is offline Copying Raw Field Codes Windows 7 64bit Copying Raw Field Codes Office 2013
Advanced Beginner
Copying Raw Field Codes
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

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
So both solutions work.

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.
Reply With Quote
  #4  
Old 01-04-2015, 02:50 PM
macropod's Avatar
macropod macropod is offline Copying Raw Field Codes Windows 7 64bit Copying Raw Field Codes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,338
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 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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Raw Field Codes 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
Copying Raw Field Codes Word Equation field codes mkarthic Word 1 12-02-2011 02:09 AM
Copying Raw Field Codes confusion with merge and field codes BluRay Mail Merge 5 03-29-2011 01:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:45 PM.


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