ProSpartan 0 Posted February 26, 2013 Report Share Posted February 26, 2013 (edited) Okay, I've searched and searched and am hoping someone here can help me out. I've been trying to get a VBScript program to open a word document, search for a specific char and replace it with a Addin field (i.e. { SEQ @ } ) Here's what I have thus far: Const wdReplaceAll = 2 Set objWord = CreateObject("Word.Application")objWord.Visible = TrueSet ObjDoc = objWord.Documents.Open("C:\path\to\.doc")Set objSelection = objWord.Selection With objSelectionobjSelection.Find.Text = "@"objSelection.Find.Forward = TrueobjSelection.MatchWholeWord = TrueobjSelection.Find.Replace.Text = "replacement text"objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll .Fields.Add .Range, -1, "SEQ @", True End With objDoc.SaveobjWord.Quit This code works for "Find/Replace" but does not work for fields.Much help would be awesome! Thanks! Edit, 27 Fed 13 (10:21 CST): In red/strikthrough is removed, plain red is added. Edited February 27, 2013 by ProSpartan Quote Link to post Share on other sites
justsomeguy 1,135 Posted February 26, 2013 Report Share Posted February 26, 2013 I doubt you can just replace with text and expect a field to be created. There's a code example on the bottom of this page that shows adding a field: http://word.mvps.org/faqs/tblsfldsfms/AddinFields.htm Quote Link to post Share on other sites
ProSpartan 0 Posted February 27, 2013 Author Report Share Posted February 27, 2013 Yes, i have seen that page already. It did work, if I remember correctly when I used it, but the program needs to find a specific char, "@", and replace it with the addin field { SEQ }. Quote Link to post Share on other sites
justsomeguy 1,135 Posted February 27, 2013 Report Share Posted February 27, 2013 I know what you're trying to do, but "{ SEQ }" is not an addin field, it is text. You're telling it to replace some text with some other text, not with a field. If you want to add a field then you need to add an actual field the way they allow you to do that. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.