[Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
shapes in Excel Object.
Since the Excel.Application
is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
interact with Excel document.
The figure below is an excel file:
Figure 1.
You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
$text = “text1”,”text2”,”text3”,”text3”
$Excel 
= New-Object -ComObject Excel.Application
$Excel.visible = $true
$Workbook 
= $Excel.workbooks.open("d:\shape.xlsx")      
#Open the excel file
$Worksheet 
= $Workbook.Worksheets.Item("shapes")       
#Open the worksheet named "shapes"
$shape = $Worksheet.Shapes      
# Get all the shapes
$i=0      
# This number is used to replace the text in sequence as the variable “$text”
Foreach ($sh in $shape){
$sh.TextFrame.Characters().text  
# Get the textbox in the shape
$sh.TextFrame.Characters().text = 
$text[$i++]       
#Change the value of the textbox in the shape one by one
$WorkBook.Save()              
#Save workbook in excel
$WorkBook.Close()             
#Close workbook in excel
[void]$excel.quit()           
#Quit Excel
Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
Besides, we can also find the documents about these methods and properties in MSDN:
Workbook.Worksheets Property (Excel):
http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
Worksheet.Shapes Property:
http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
Shape.TextFrame Property:
http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
TextFrame.Characters Method (Excel):
http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
Characters.Text Property (Excel):
http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
After running the script above, we can see the changes in the figure below:
Figure 2.
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

Thank you for the information, but does this thread really need to be stuck to the top of the forum?
If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
EDIT: I see this is no longer stuck to the top of the forum, thank you.
Don't retire TechNet! -
(Don't give up yet - 13,085+ strong and growing)

Similar Messages

  • Find and Replace text string in HTML

    Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
    with "YYYYY"
    I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
    [email protected]

    Hello Phil,
    The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
    questions there.
    If you decide to develop an Outlook macro on your own, the
    Getting Started with VBA in Outlook 2010 article is a good place to start from.

  • How to find and replace any string between " "

    Hi everyone,
    Here my sample
    String szTest;
    szTest = "Yellow banana";
    szTest = "Blue monkey";
    szTest = "Red mango";
    szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
    So Here what I want after using the Find and Replace Box:
    //String szTest; //Manual
    /*szTest = "Yellow banana";*/ //use find and replace
    /*szTest = "Blue monkey";*/ //use find and replace
    /*szTest = "Red mango";*/ //use find and replace
    I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
    Find: szTest = " ??Any string?? ";
    Replace with: /*szTest = " ??Any string?? ";*/
    Thanks for reading.

    Hi Nathan.j.Smith,
    Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
    maybe you will get some useful message.
    https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
    If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
    issue?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to find and replace text in Excel with Automator

    I am new to Automator. And I would like some help how I can create a service that will allow me to find and replace certain text in Excel. I noticed that there is an action to do this for Word documents, but not for Excel document.
    Any suggestions how I can do this?
    Thanks so much for your help.

    Easiest way to do it is the following:
    - Open the PDF file in Acrobat.
    - Go to Tools - Forms - More Form Options - Export Data.
    - Save the form data as an XML file somewhere on your system.
    - Open XML the file in a plain-text editor (I recommend Notepad++).
    - Let's say you want to replace all the years in the dates from "2013" to "2014". Do a global Search&Replace of "2013-" to "2014-" (I added the dash just to make sure that only date fields are edited).
    - Save the XML file (maybe under a new name).
    - Go back to the PDF file, and now go to Tools - Forms - More Form Options - Import Data.
    - Select the edited XML file and import it.
    - Done!

  • Use VBA and Excel to open Dreamweaver HTML (CS5), find and replace text, save and close

    I wish to use VBA and Excel to programmatically open numbered Dreamweaver HTML (CS5) and find and replace text in the code view of these files, save and close them.
    I have  5000 associations between Find: x0001 and Replace: y0001 in an Excel sheet.
    I have the VBA written but do not know how to open, close and save the code view of the ####.html files. Please ... and thank you...
    [email protected]

    This is actually the code view of file ####.html that I wish to find and replace programmatically where #### is a four digit number cataloguing each painting.... In 1995 I thought this was clever... maybe not so clever now :>)) Thank you for whatever you can do Rob!
    !####.jpg!
    h2. "Name####"
    Oils on acrylic foundation commercial canvas - . xx X xx (inches) Started
    Back of the Painting In Progress </p> </body> </html>
    Warmest regards,
    Phil the Forecaster, http://philtheforecaster.blogspot.ca/ and http://phils-market.blogspot.ca/

  • Folder action to find and replace text and change line feeds

    I want to use a folder action to find and replace text and change Mac carriage returns to DOS line feeds inside text files.
    The text to be replaced is: "/Users/wim/Music/iTunes/iTunes Music/Music" (without the quotes)
    This text has to be removed (i.e. replaced by an empty string)
    The text occurs many times within each file.
    The files are playlists exported from iTunes in the M3U format (which are text files). They contain Mac carriage returns. These need to be changed to DOS line feeds.
    I have found the following two perl commands to achieve this:
    To find and replace text: perl -pi -w -e 's/THIS/THAT/g;' *.txt
    To change carriage returns to line feeds: perl -i -pe 's/\015/\015\012/g' mac-file
    I know that it's possible to make a folder action with Automator that executes a shell script.
    What I want to do is drop the exported playlists in M3U format in a folder so that the folder action will remove the right text and change the carriage returns.
    My questions are:
    Is it possible to make a folder action that executes command line commands instead of shell scripts?
    What is the correct syntax for the two commands when used in a folder action shell script? Especially, how do I escape the slashes (/) in the string to be removed?
    Thanks for your help

    Ok, I've include an applescript to run a shell command. The applesript command quoted form makes a string that will end up as a single string on the bash command line.  Depending on what you want to do, you may need multiple string on the bash command lines.  I've included some information on folder actions.
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set desktopPath to (path to desktop) as string
        log "desktopPath = " & desktopPath
        set unixDesktopPath to POSIX path of desktopPath
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "ls -l  " & quotedUnixDesktopPath
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run
    How to set up a folder action.
    1) right click on folder. click on Enable folder actions
    2) Place script in
    /Library/Scripts/Folder Actions Scripts
    3) right click on folder. click on attach folder action
    pick your script.
    Create a new folder on the desktop & try.
    You can put multiple folder actions on a folder. There are other ways of doing this.
    Here is my test script:
    on adding folder items to this_folder after receiving dropped_items
        repeat with dropped_item_ref in dropped_items
           display dialog "dropped files is " & dropped_item_ref & " on folder " & this_folder
        end repeat
    end adding folder items to
    How to  make the text into an AppleScript program.
    Start the AppleScript Editor
    /Applications/AppleScript/Script Editor.app
    In Snow Leopard it's at: /Applications/Utilities/AppleScript Editor
    Copy the script text to the Applescript editor.
    Note: The ¬ is typed as option+return.  ption+return is the Applescript line continuation characters.
    You may need to retype these characters.
    Save the text to a file as an script and do not check any of the boxes below.

  • How to find and replace data in form fields in acrobat xi, its not allowing to do so while trying, a

    how to find and replace data in form fields in acrobat xi, its not allowing to do so while trying, asking for adobe livecycle to get installed. please help.

    Easiest way to do it is the following:
    - Open the PDF file in Acrobat.
    - Go to Tools - Forms - More Form Options - Export Data.
    - Save the form data as an XML file somewhere on your system.
    - Open XML the file in a plain-text editor (I recommend Notepad++).
    - Let's say you want to replace all the years in the dates from "2013" to "2014". Do a global Search&Replace of "2013-" to "2014-" (I added the dash just to make sure that only date fields are edited).
    - Save the XML file (maybe under a new name).
    - Go back to the PDF file, and now go to Tools - Forms - More Form Options - Import Data.
    - Select the edited XML file and import it.
    - Done!

  • In Pages, how to search and replace text involving invisible characters?

    In Pages documents, how to search and replace text involving invisible characters, colors and font sizes—a task which is so easy in Mircosoft Word?

    I read that an older version of Pages allowed users to enter special characters in the search/replace fields, but this did not work for me.
    Here: http://www.macworld.com/article/1156533/pagesspecialcharacters.html
    I still am looking for a way to do this.

  • HT2905 Does anyone know how to find and remove duplicate items in the new itunes 11?

    I am having a hard time trying to figure out how to find and remove duplicate items under the New iTunes 11? Its not as user friendly as in previous versions. Does anyone know how to figure this out?

    As Jim said View > Show Duplicates
    or
    Option + View > Show Exact Duplicates

  • How do I find and replace text in PHP files?

    How can I in CS3 make sitewide changes to the text in PHP pages without changing variable names etc that have the same name?
    For example if I have an installation of a PHP forum and I want to change every instance of the word 'forum' to 'message board'...
    If I used the 'inside tag' search with " as the tag, then if "" contained a variable called 'forum' it would also be changed and therefore corrupt the code....
    Is there a simple way around this?
    Thanks!
    I'm using CS3 on Windows Vista.

    It looks like you're trying to find and replace source code, so you may be able to look at the various places that are looked at when finding and uncheck the ones that don't apply.
    But, if it's all source code then that won't help.  One thing that may work is to expand the search option - for example if the work "forum" that you're wanting to change it preceded by another word, or character or something that sets it apart, then do you find on that. You can expand that search phrase as far out in either direction that you need to to make it different, if of course that is practical in your situation.
    The only other way I can think of is to somehow create an exception rule, but I'm not sure if that's possible or how to do it.

  • How to find and replace certain text in Excel.

    I am new to Automator. And I would like some help how I can create a service that will allow me to find and replace certain text in Excel. I noticed that there is an action to do this for Word documents, but not for Excel documents.
    Any suggestions how I can do this?
    Thanks so much for your help.

    Marga,
    I think the best place to ask about Office for Mac would be in the MS forums.
    Jerry

  • How to find and replace the text present in the url

    I have a column of type NCLOB with some text having url's in between as shown below:
    ========================================================================
    This text is for testign purpose.This text is for testign purpose.
    <A PL/SQL <U PL/SQL </U> </A>
    Thsi text is also for testign purpose.This text is for testign purpose.
    <A http://forums.oracle.com> <U oracle metalink> </U> </A>
    This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.
    ========================================================================
    Requirement:
    ========
    Requirement is to implement the find and replace functionality.
    I just need to check whether the search text is present in the url or not?
    Suppose if search for orcale.com, since its part of the url so the search should be successful otherwise search should be unsuccessful.
    Here I can give you the hint like, always the url lies between the anchor tags *(<A </A>).*
    Tahnks in Advance.

    I had I think a similiar question the other day thay I Frank and Michaels answered for me.
    not sure if I totally have what you want but.
    WITH t
            AS (SELECT '<A PL/SQL <U PL/SQL Thsi text is also for testign purpose.This text is for testign purpose.
    <A http://forums.oracle.com> This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.This text is for testign purpose.
                          txt
                  FROM DUAL)
    SELECT REGEXP_SUBSTR (REGEXP_REPLACE (txt, '(.*<A)|(</A>.*)'), 'oracle.com')
      FROM tthe first part the regexp replace part gets the text between a start and end point you mentioned that would be <A and </A>
    the regexp substr just looks for the phrase oracle.com in the text between those two points.
    Edited by: pollywog on Oct 6, 2010 8:26 AM

  • How to find and replace multiple cells at a time

    I am doing repetitive work re find text in numbers but then replace following cells with text. How can I find and replace multiple cells at a time?
    i.e. doing my own budget spreadsheet and coding all transactions with description and code

    Did you try the "Find/Replace" dialog box?:
    Then click the "Replace All" button in the bottom left.

  • Find and replace text in multiple Photoshop files?

    Hi there,
    Let us say I have six Photoshop files: 1.psd, 2.psd, ..., 6.psd. All of these files contain the word “LoremIpsum” in random text layers, within each document. Is there a way I can search for “LoremIpsum” in all documents and replace it with “Dolor Sit Amet”, all in one go? This is just an example, I need to replace various words, not just one.
    I have tried "batch find and replace" software (including powerful tools like Power Grep) but they do not work with psd files… Is there a javascript of external plugin for this kind of task?
    Thanks!

    You’re welcome, advice given here is free.
    If you want to donate something nonetheless you could do so over at
    http://ps-scripts.com/bb/
    Many of the same people used to contribute there as here and I for one have benefitted considerably from their generous advice on Scripting issues.
    A Script can read (or create) txt files, but I do not have a lot of experience with this.
    This might work (amend the line »var theTexts = readPref ("….txt", false);« according to your txt-file’s path):
    // replace text elements in type layers;
    // 2013, use it at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
              for (var n = 0; n < app.documents.length; n++) {
                        app.activeDocument = app.documents[n];
                        app.activeDocument.suspendHistory("replace text", "main()")
    // the opertation;
    function main () {
              var myDocument = app.activeDocument;
              var theTexts = readPref ("….txt", false);
              var theArray1 = theTexts.slice(0, Math.round(theTexts.length/2));
              var theArray2 = theTexts.slice(Math.round(theTexts.length/2), theTexts.length);
              alert (theArray1.join("\n")+"\n\n\n"+theArray2.join("\n"))
              for (var b = 0; b < theArray1.length; b++) {
                        replaceText (theArray1[b], theArray2[b])
    ////// reoplace text //////
    function replaceText (replaceThis, replaceWith) {
    // =======================================================
    var idreplace = stringIDToTypeID( "replace" );
        var desc22 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idPrpr = charIDToTypeID( "Prpr" );
            var idreplace = stringIDToTypeID( "replace" );
            ref3.putProperty( idPrpr, idreplace );
            var idTxLr = charIDToTypeID( "TxLr" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idAl = charIDToTypeID( "Al  " );
            ref3.putEnumerated( idTxLr, idOrdn, idAl );
        desc22.putReference( idnull, ref3 );
        var idUsng = charIDToTypeID( "Usng" );
            var desc23 = new ActionDescriptor();
            var idfind = stringIDToTypeID( "find" );
            desc23.putString( idfind, replaceThis );
            var idreplace = stringIDToTypeID( "replace" );
            desc23.putString( idreplace, replaceWith );
            var idcheckAll = stringIDToTypeID( "checkAll" );
            desc23.putBoolean( idcheckAll, true );
            var idFwd = charIDToTypeID( "Fwd " );
            desc23.putBoolean( idFwd, true );
            var idcaseSensitive = stringIDToTypeID( "caseSensitive" );
            desc23.putBoolean( idcaseSensitive, false );
            var idwholeWord = stringIDToTypeID( "wholeWord" );
            desc23.putBoolean( idwholeWord, false );
            var idignoreAccents = stringIDToTypeID( "ignoreAccents" );
            desc23.putBoolean( idignoreAccents, true );
        var idfindReplace = stringIDToTypeID( "findReplace" );
        desc22.putObject( idUsng, idfindReplace, desc23 );
    executeAction( idreplace, desc22, DialogModes.NO );
    ////// read prefs file //////
    function readPref (thePath, binary) {
      if (File(thePath).exists == true) {
        var file = File(thePath);
        file.open("r");
        if (binary == true) {file.encoding= 'BINARY'};
        var theText = file.read();
        file.close();
        return String(theText).split(",")
    In this case the comma is used to split the text into Strings in Arrays, if your search/replace texts include commas you could use something else, I guess.

  • Find and Replace text in files

    Is there a function that will find and replace a word in a few text files at once. E.G replace the word database1 with database2 without going into each script individually and doing and search and replace.

    Andrew, you are being so cruel, hardnuts indeed ;)
    I won't mention any names, but at least it's not as cruel as some people saying “You may read DBMS_STATS package specification, at least, to get details, if you're too lazy to read manuals.”
    Personally I prefer to use a development tool (TOAD, Pl/Sql Developer) instead of a Text type editor.

Maybe you are looking for