Excel & Powershell: Bulk Find and replace URL's used in forumlas

Hi, I'm working on creating a script that I will provide a list of SharePoint 2007 document libraries to which will do the following:
In Excel, find formulas within cells that link to other workbooks + sheets (XLS/XLSX)
If found, replace the formula link http://serverold/site/doclib/ with
http://servernew/sites/sitecollection/doclib and save
Else, close the workbook and move onto the next
Log full URL and filename of any changes
Using the code on this
link  as my starting point I cannot get the following working:
1. The regex expression to make the script detect the URL in the formulas
2. modify the script to replace the old path with the new path in the formula within cells.
3. a for each branch to deal with when the match is found (save and close) and when it's not found (just close)
I'm not going into detail on all the research I've done (info is very light on the ground), just that it is mentioned on another thread that you can enumerate these
links centrally in Excel but no example or links were given and when I've tried to enumerate the links collection in PowerShell (with Excel 2010 installed) it is empty with the example workbook I'm using which I know as "links" in that sense. 
Example to enumerate link collections:
$File = "C:\temp\example.xls"
$Excel = New-Object -ComObject Excel.Application
$Excel.visible = $true
$Workbook = $Excel.workbooks.open($file)
$Workbook.LinkSources
So it begs the question, which method is right?
Example Excel formula
=+'http://serverold/site/site/Work in Progress Documents/Statements/[Hierarchy2011.xls]Reports'!$AD$37+'http://serverold/site/site/Work in Progress Documents/
Script to enumerate links (from the link I mentioned as my starting point) - 
$path = "C:\temp"
$excelSheets = Get-Childitem -Path $path -Include *.xls,*.xlsx -Recurse
$excel = New-Object -comobject Excel.Application
$excel.visible = $false
foreach($excelSheet in $excelSheets)
$workbook = $excel.Workbooks.Open($excelSheet)
"There are $($workbook.Sheets.count) sheets in $excelSheet"
For($i = 1 ; $i -le $workbook.Sheets.count ; $i++)
$worksheet = $workbook.sheets.item($i)
"`tLooking for links on $($worksheet.name) worksheet"
$rowMax = ($worksheet.usedRange.rows).count
$columnMax = ($worksheet.usedRange.columns).count
For($row = 1 ; $row -le $rowMax ; $row ++)
For($column = 1 ; $column -le $columnMax ; $column ++)
[string]$formula = $workSheet.cells.item($row,$column).formula
if($formula -match "\w?:\\\w*\\\[\w*\.xls\w?\]") {"`t`t$($formula)"}
} #end for $column
} #end for $row
$worksheet = $rowmax = $columnMax = $row = $column = $formula = $null
} #end for
$workbook.saved = $true
$workbook.close()
} #end foreach
$excel.quit()
$excel = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
Thanks to anyone who can help and for your time.
Bests,
Ash

Hi,
Just checking in to see if the suggestion was helpful. Please let us know if you would like further assistance.
TechNet Subscriber Support
If you are
TechNet Subscription
user and have any feedback on our support quality, please send your feedback
here.
Cataleya Li
TechNet Community Support

Similar Messages

  • [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)

  • Can't find and replace on one column only

    in Excel I could find and replace something that where on one column.
    In Numbers I can find and replace on all the document, active sheet or formula, but not on the selected column i.e.
    Does anyone know any trick for that?
    Cheers
    Olivke

    Hi Olivke,
    Welcome to Apple Discussions and the Numbers '09 forum.
    Of the three choices, the one that seems most immediately useful in "on the active sheet."
    To use that, you'll have to isolate the column (or it's contents) on a separate sheet, and make that the 'active sheet.'
    I would recommend making duplicates of your file to use when trying each of these methods.
    Start by inserting a new sheet. Then go back to the 'current sheet', select the column, and Copy.
    Click on the new sheet to bring it to the front, click on the top body cell (B2) of the empty table that came with that sheet and Paste.
    Do Find/Replace, restricting the action to the Current Sheet.
    Select the column, Copy, return to the original, Select the column, Paste.
    Second method...
    Starts the same way, but this time select and delete the table that comes with the New Sheet.
    On the original table, click on any cell to make the table active and show the column and row reference tabs.
    Use the mouse to grab the reference tab of the column you want to search, and drag it upward until you see it separate from the rest of the table. Continue to drag it until it is completely separated from the table, then drop it on the sheet. In the sidebar, you'll see a new table icon for this one column table. Drag the icon down to a position below the icon for the new sheet you created above.
    When you drop the icon, the new sheet will be come the current sheet, and will come to the front with the one column table selected.
    Do Find/Replace, restricting the action to the current sheet.
    When finished, drag the one column table back to its original sheet, using the icon in the sidebar.
    On the original sheet, click on a cell to make the one column table active. Grab the column reference tab and drag the column back to its original position in the original table.
    Done.
    Regards,
    Barry

  • 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.

  • 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/

  • How do I create a multiple find and replace for Excel in AppleScript?

    I have a large dataset in Excel that I have to do a multiple find/replace in (changing USPS state abbreviations to their full names). In searching the Microsoft boards--I was directed to use Applescript, and even the documented help with Excel was recommeding this. Unfortunately, there wasn't much help potinting me in the specific direction I needed. Any ideas on how I should write this script?
    Thanks!

    I'm confused as to why Applescript (or any script would be helpful).
    You'd have to type the abbreviation and the full name into the script, the same as just using Find and Replace All. You wouldn't gain anything by using a script. Is there more to this task than you've let on?
    MacTech has an article on converting from VBA to Applescript, but I'm not sure if it would have any ideas on your specific problem: http://www.mactech.com/vba-transition-guide/index-toc.html

  • 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!

  • 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 replacing the path (url) given for data binding from type 'datasocket'

    Hi everyone,
    I'm sorry to pose this question as my own knowledge is still very limited.
    I have an assignment (bachelor level). We were asked to adjust a plc program in step7 so that multiple of an existing sequence could be run indepently.
    The settings for that sequence are controlled by labview. Sensor data is also viewed in labview.
    There is an existing labview VI that was made by someone else before us. It uses 'Datasocket' type for data binding. Because we would like to adjust this VI to be used with the other sequences, we would like to change the original path or URL quickly, as in a 'Find&Replace' solution. Yet the find and replace only works for objects or text, not entries in the properties.
    Can someone please tell me if there is a way to do is, without having to use shared variables, as we are not at all known with this type.
    Many thanks,
    Niels

    Dear Niels,
    Please find the attached example. I placed 5 controls on the front panel, all with a data socket URL (control 1 = URL1, control 2 = URL2 etc). Through property nodes I did the following;
    - I got a reference to the front panel
    - with this reference we can get an array of references to the controls on this front panel
    - one by one we will read the references and check the data socket URL from the control, we compare this with the URL we are searching
    - if found, stop we will use the reference to write a new URL to the control.
    Please notice the default values of the controls; it is set to search for URL3 and replace this with URL10, run the VI once and you will see that happening. I also included a sting indicator which will show you the label of the control which we find. Also a Boolean indicator in case we were not able to find the URL.
    I downsaved the VI to 8.6, I'm not sure in which version you are working, if you have 8.6 or higher you are able to open it. Hope this brings you further,
    Best regards,
    Martijn S
    Applications Engineer
    NI Netherlands
    Attachments:
    findURLexample.vi ‏12 KB

  • 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 can I change a VI that is linked to "NI_Excel.lvclass:Excel Find and Replace (str).vi

    I need to create a new VI from, "Excel Find and Replace (str).vi", for my own purposes.
    LabVIEW will not allow me to do this, because that VI belongs to, "NI_Excel.lvclass."
    Intead of find and replace - I would like it to find a string, and tell me what column and row it is at.
    Thank You
    Solved!
    Go to Solution.

    Have you searched the discussion forums for this, even the Excel board?
    You'd probably find what you want, or at least something close that you could learn from.
    Can you open up the VI that you are asking to change?  Even if you aren't permitted to copy it, if you open it and see what it does, you can recode it yourself using the appropriate ActiveX functions.

  • Find and Replace from a list?

    I have a 400 page indesign brochure. It contains 3000 codes. I want to change those 3000 codes to links (existing code the word to click on - not the view of full url). I have a csv file with all codes (col 1) and full http link (col 2). Anyone help me with a find and replace? I have CS5.5 (very poor see) - my knowledge is pretty poor as I have not used the program for a few years. I would appreciate any help.

    Take a look here Re: FindChangebyList with strings of text? I think #12 is what you want.
    You might need to sort the order of the excel list according to the length of the word from longest to shortest.
    To do that in cell C1 type =LEN(A1)
    Copy that to the whole column apply the sort to the table from largest to smallest and then erase the whole column C save the file and it's ready for the script.
    I would have written the script differently now as my skills have improved significantly, adding a sort function in the script would be very easy but I'm very busy now.
    Trevor

  • VBA Word Find and Replace characters but excluding certain characters

    I am trying to write VBA code in Word that I will eventually run from a VBA Excel module. The aim of the project is to find specific strings in the open Word document that have length of either one or two characters and are of a certain format, and replace
    them with other strings in the same format. This is to do with transposing (i.e. changing the musical key) of chord symbols in a songsheet in Word. The Find and Replace strings are contained in ranges in an Excel workbook, which is why I want to eventually
    run the code from Excel. I'm much more experienced in writing VBA code in Excel than in Word, and I'm fairly confident with transferring the 'Word VBA' code into an Excel module.
    At the moment I'm trying out code entirely in Word, and I've come across a stumbling block. For example, I want it to Find "A" and replace with "B",
    BUT only if the "A" is NOT followed by "#" (sharp) or "b" (flat).
    Here is the code I've got in Word VBA, which I obtained by editing code produced by the recorder:
    Sub F_R()
    'Find text must have specific font
    With Selection.Find.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Replacement text must have specific font
    With Selection.Find.Replacement.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Find & Replace strings
    With Selection.Find
    .Text = "A" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Replacement.Text = "B" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    For the Find & Replace section I want to do something like:
    With Selection.Find
    .Text = "A"
    .Text <> "A#"
    .Text <> "Ab"
    .Replacement.Text = "B"
    End With
    - but this produces a syntax error, presumably because you can have only one .Text line (or it won't accept <>?)
    I tried adopting the way of excluding chars when using the Like operator, and while it compiles, it will not replace
    any "A":
    With Selection.Find
    .Text = "A[!b#]"
    .Replacement.Text = "B"
    End With
    I suspect that I'm going to have to change tack completely in the way I'm doing this. Do you have any suggestions, please?
    The chord names/symbols are preceded/succeeded by either spaces or paragraph returns and can look like these, for example (all Font Bold and Underlined words only):
    C<sup>7</sup>
    Dm<sup>7</sup>
    Eb<sup>-5</sup>
    Bb<sup>+11</sup>
    F#m<sup>7</sup>
    i.e. [ABCDEFG][b # | optional][m |optional][- + | superscript, optional][2 3
    5 6 7 9 11 13 | superscript, optional]
    The crux of my problem is that the note A should be treated as entirely distinct from Ab or A# (and similar for other flattened/sharpened notes).
    Sorry for long post.

    Hi Ian,
    It is not easy to find Microsoft forums. However this forum is for the Visual Studio Net version. 
    Try this forum for VBA.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba
    Success
    Cor

  • 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.

  • A Script to Find and Replace Layer Names

    Are there any scripts to find and replace layer names?
    There is an excellent script available for Photoshop which allows you to not only replace words in layer names, but also insert words as Prefixes, Suffixes and Sequential Numbers.
    The illustrator version of this script only allows sequential numbering: It doesn't offer find and replacing of words.
    Ideally, it would be great if there was something that could do multiple find and replaces in one go:
    (e.g.
    You have layers like this Car, Dog, Bat
    You enter: car(Option1), dog(Option2), Bat(Option3)
    Your layers then become: Option1, Option2, Option3).

    big_smile, that's a very good start! Step 1 of Learning How To Script is indeed, adjusting an existing simple script to make it do more complicated things. (And usually then "break something", which is also a required part of the process.)
    You are correct in your observation this is repetitive stuff. For one or two different items that wouldn't be a problem, but in longer lists you soon get lost.
    The usual way of working with find-change lists is to build an array:
    var layernames = [
    [ 'FHairBowlBoy *Hair', 'Hairboy1' ],
    [ 'FHairCurlyafroBoy *Hair', 'Hairboy2' ],
    [ 'FHairSpikyBoy *Hair', 'Hairboy3' ],
    The general idea is to loop over all names, check if the current layer name is "layernames[i][0]" (the left column) and if so, rename it to "layernames[i][1]" (the right column). If you know how to write a loop in Javascript, then you can implement this right away.
    However ..
    A more advanced way to do this doesn't even need loop to over all layernames -- instead you can immediately "get" the correct name per layer! It's magic! Almost!
    The trick is to use a Javascript object instead of an array. Javascript objects are nothing special; Illustrator's 'layers' is an array of objects, and each object "layer" has a property "name", whose value you can read and set. What I do here is create a new object, where the "name" part is the original layer name and its value is the new layer name. All you need to check for per each layer is if there is a property 'object.originalLayerName', and if so, assign its value to that layer name.
    This looks a bit like the array above, except that (1) you use {..} instead of [..] to create an object, and (2) you add "name:value" pairs instead of "value" only (actually, the 'name' of a value in an array is simply its number).
    So this is what it looks like:
    // JavaScript Document
    var doc = app.activeDocument;
    // name indexed object
    var layernames = {
    'FHairBowlBoy *Hair':'Hairboy1',
    'FHairCurlyafroBoy *Hair':'Hairboy2',
    'FHairSpikyBoy *Hair':'Hairboy3'
    // loop through all layers
    for (var i = 0; i < doc.layers.length; i++)
    //Set up Variable to access layer name
    var currentLayer = app.activeDocument.layers[i];
    if (layernames[currentLayer.name])
      currentLayer.name = layernames[currentLayer.name];
    Enjoy!

Maybe you are looking for

  • Aperture Dual monitors, what video card for AGP?

    I am running two 20 inch apple monitors with the stock ATY 128 mb card. I am going to be upgrading the card soon because the system is so slow. I know that I am limited because this system can only use AGP cards. What is the best AGP card available?

  • How can I close the finder application

    I need to know how to close the finder application because there have been many downloads that I cannot do unless all applications are closed. if you cannot then owners of mac please make it possible because (no offense) if not downloads are useless

  • Sound Recorder activated automatically in WhatsApp

    I was very suprised when recently a friend of mein noted that he has received a 22 minute voice recording message over WhatsApp. I found out that the integrated Sound Recorder had recorded a message acitivating and sending it out without my knowledge

  • What oracle forms / reports version are using in EBS R12?

    Hi all, We are planning to upgrade to EBS R12. what oracle forms / reports version are using in EBS R12? Thanks.

  • An irrecoverable stack overflow  on RedHat7.1 Linux WLS6.1 SP2

    Does somebody knows this type of problem,please ? We have 2 processor Linux machine Hardware: VALinux Dual CPU 550Mhz with 1GB Ram, 8GB SCSI HDD. Server type and Kernel build: Linux Linda 2.4.5-beta4va3.15smp-piii #1 SMP Fri Jun 15 04:29:19 PDT 2001