ProSpartan Posted February 26, 2013 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted February 26, 2013 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 Link to comment Share on other sites More sharing options...
ProSpartan Posted February 27, 2013 Author 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 }. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now