I have a Word document with text in tables and text outside tables. I want to find and replace in all the text, not just the text outside the tables. The content property of the document is just the "main story" and not the tables. I don't want to iterate through all the table objects. I just want to find and replace in all the text, just like when I do it manually using the Word gui.
Please save me from the mental hell I am burning in.
[The stench of burning flesh is starting to worry me. Almost as much as the excruciating pain in my extremities.]
[My legs and arms have been devoured by the flames. I write this with my nose, which is sticky with melted plastic from the keys.]
Use the Find property, it is the same as the UI. Search help topic for "Find Property" to get you started.
With ActiveDocument.Range.Find
.Text = "hi"
.Replacement.Text = "hello"
.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
End With
Related
So what I am trying to do is I want to fetch Heading wise data from word via docx4j and want to replace the data that is in those Headings, I do not want to change the heading text just want to remove all the things in that Heading and replace it with another. I searched everywhere for 4 days but not able to find a successful way of doing it, I can do it by fetching text line by line manually but that won't be efficient so is there any way I can directly get Heading wise data and thn can remove every child in that Heading and append another child in that same heading?
Below I have attached an image of the word document, so thing is I want to remove everything in the Heading1 i.e. "2. Functional Requirements" but I do not want to change the heading or it's heirarchy, I just want to remove everything i.e. 2.1.1 and it's subdata, 2.1, BR_1,etc and want to append data same way here as child of "2. Functional Requirements" Style - Heading1.
Below is the image of the word document:
Please Help me, any help is highly appreciated.
Thank you, have a great day.
I have an SSRS report that has Spanish and English text boxes. If the dataset row is a Spanish speaking person, an expression in each Spanish textbox shows that and hides the English textbox. These textboxes are exactly placed over each other.
My boss wants me to use SSRS to generate an Excel spreadsheet from the dataset(this is not hard) and use Word template for a mail merge. However, I am having trouble trying to figure out if I can hide all English when row is a Spanish row and vice versa. These are health clients of Spanish and English nationality.
I can do mail merges attached to a Recordset, I can do one in English, one in Spanish. I am trying to avoid this and have it all in one Mail Merge.
Areas marked in red will change to Spanish translation and/or date format. The dates are a no-brainer I can use a conditional IIF, however the formatted body I have no solution for, based on value in Field "CL_Language" which is either "Spanish" or "English".
====================================
The merge fields for dates and greeting are easy. There is no merge field for the text. And yes, only option might be for 2 separate reports with different Recordsets.
It's not clear what the actual issue is but...
Instead of hiding textboxes, which could cause problems when exporting etc., why not set a single textbox to the correct language text using an expression?
Something along the lines of
=IIF(Fields!Language.Value = "English", Fields!MyEnglishText.Value, FieldsMySpanishText.Value)
I found a solution. But it could be very difficult for the client to create. It involves hitting Ctrl + F9 which will create curly brackets {}.
Inside those curly brackets an IF statement is placed and I just pasted the whole Spanish formatted body in the true area, and the whole English body in the false area.
{IF "CL_Language" = "Spanish" "spanish body text here" "english body text here"}
Very strange syntax and you need to right click on the area to see choices like "Toggle Field Codes" (IF statement get's hidden), "Edit Field", and "Update Field". With Edit Field and Update Field you get a popup with the fields in your recordset.
If you saw the examples in my question, you can see that is some big clunky text AND . . .inside of it is a merge field that works! The Excel recordset comes already with the month name in correct language for each row.
Since it is not smart to include links that might expire, I am including the Google text I used to find this solution. Then I took a chance on a huge formatted chunk of text with a merge field inside of it.
Google this: "If Merge Field then"
Now is this a viable solution for the client versus just having a Word template for each language?
I think this is too difficult and I even duck when running it. Also, once it's working, if I look at the toggled code, the Conditional field no longer says the field name, but the value in the field, go figure.
{IF "Spanish" = "Spanish" or {IF "English" = "Spanish" instead of {IF "CL_Language" = "Spanish" or {IF "CL_Language" = "English"
Here is how to access the fields using right click. (remember, your curly brackets HAVE to be created with Control + F9).
I'm trying to add a hyperlink object inside a Word comment.
To create a new comment in the active document I'm using this piece of script:
tell application "Microsoft Word"
set tempString to "lorem ipsum"
make new Word comment at selection with properties {comment text:tempString}
end tell
but now I'm not able to get a reference to the new created comment for use it with the command "make new hyperlink object".
Thanks for any suggestions.
Riccardo
I don't think you can work with the object returned by make new Word comment (at least not in this case), and you have to insert a unique, findable string then iterate through the comments:
tell application "Microsoft Word"
-- insert a unique string
set tempString to (ASCII character 127)
set theComments to the Word comments of the active document
repeat with theComment in theComments
if the content of the comment text of theComment = tempString then
set theRange to the comment text of theComment
-- you do not have to "set theHyperlink". "make new" is enough
set theHyperlink to make new hyperlink object at theRange with properties {text range:theRange, hyperlink address:"http://www.google.com", text to display:"HERE", screen tip:"click to search Google"}
insert text "You can search the web " at theRange
exit repeat
end if
end repeat
end tell
(edited to insert some text before the Hyperlink. If you want to insert text after the hyperlink, you can also use 'insert text "the text" at end of theRange.).
So for adding text, it was enough to use "the obvious" after all.
[
For anyone else finding this Answer. The basic problem with working with Word ranges in Applescript is that every attempt to redefine a range in the Comments story results in a range that is in the main document story. OK, I may not have tried every possible method, but e.g., collapsing the range, moving the start of range and so on cause that problem. In the past, I have noticed that with other story ranges as well, but have not investigated as far as this.
Also, I suspect that the reason why you cannot set a range to the Word comment that you just created is because the properties of the Comment specify a range object of some kind that I think is a temporary object that may be destroyed immediately after creation. SO trying to reference the object that you just created just doesn't work.
This part of the Answer is modified...
Finally, the only other way I found to populate a Comment with "rich content" was to insert the content in a document at a known place, then copy its formatted text to the comment, e.g. if the "known place is the selection, you can set the content of theComment via
set the formatted text of the comment text of theComment to the formatted text of the text object of the selection
If you are using a version of Word that supports VBA as well as Applescript, I don't really see any technical reason why you shouldn't invoke VBA to do some of these trickier things, even if you need the main code to be Applescript.
]
Finally I got a solution here:
https://discussions.apple.com/message/24628799#24628799
that allowed me to insert the hyperlink in reference with part of the comment text, with the following lines, if somebody in the future will search for the same:
tell application "Microsoft Word"
set wc to make new Word comment at end of document 1 with properties {comment text:"some text"}
set ct to comment text of wc
set lastChar to last character of ct
make new hyperlink object at end of document 1 with properties {hyperlink address:"http://www.example.com", text object:lastChar}
end tell
I am trying to insert two documents in to a collection called hi.
Hear one document is inserted and other one is not inserting..
for understanding i keep the values as blue and red for pp field.
when i am inserting blue its inserted.
and when i insert red its not inserted
db.hi.insert({city:"ny",pp:"blue"})
this doc is inserted
if in this place and in this doc if i changed pp field to red or any thing its inserted
db.hi.insert({city:"ny",pp:"red"})
this doc is not inserted
but in this place if i changed it to blue or any thing also it wont insert
may be some thing like place holder s some thing i don't know what is this.. that's why i make a video for this ..
very STRANGE..
i made a video(recorded).. please watch in mute and in HD
and i know if you tried in you system it will work but for me its not worked .. that's why i make a video
Hear is the link i uploaded.
There is an invisible character in the code, right after the semicolon. It's the Unicode U+200B Zero-width space character. Instead of pressing "up" on your keyboard, try writing the insert statement again from scratch.
See also: No visible cause for "Unexpected token ILLEGAL"
i want to use automatic numeration of Figures by word. When i insert a caption, I can choose what kind of caption this is, and since i have a different language than english, i made a new Type "Figure". The problem is with referencing: When i insert a cross reference onto that figure, it inserts it as "Figure" and makes it bold, since i embolden the "Figure" part of the caption, to make it more visible.
How can i change this in the text to be abbreviated with "fig."? Its annoying that the capitalisation is wrong and that the whole word "Figure" is inserted, instead of just the abbreviation. How can i accomplish that?
In Word 2007 you can in the "Insert Caption" dialog check whether to include or exclude the label from the caption. So inserting a reference will make you show only the number, without "Figure" word, so you can type "Fig." manually.
(Picture taken from http://word.tips.net/T000890_Adding_Captions.html)
As far as I know it is not possible (this way) until Office 2007.