Help writing a excel function to a cell using powershell

I have been working on a function that will write worklog information to an excel template. I am able to get it to work but once i added the date column and tried to write a excel function to it I'm getting the below error.
Exception setting "Item": "Exception from HRESULT: 0x800A03EC"At
C:\Users\shuppz\Documents\WindowsPowerShell\Modules\Client Config CDRL\Source\Get-Assignment.ps1:1482 char:4
+ $Main.Cells.Item($i, 9) = $DateFunction
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertySetValueTI
the excel string i need to add to the cell is to add a date and the string i created is in the below function called $DateFunction.
Function Create-Worklog
Param ($NewFile, $DBName, $Work)
$before = @(Get-Process [e]xcel | %{ $_.Id })
$ExcelObject = new-Object -comobject Excel.Application
$ExcelId = Get-Process excel | %{ $_.Id } | ? { $before -notcontains $_ }
$ExcelObject.visible = $False
$ExcelObject.DisplayAlerts = $False
$ActiveWorkbook = $ExcelObject.WorkBooks.Open($NewFile)
$Main = $ActiveWorkbook.Worksheets.Item('Worklog')
$Main.Cells.Item(2, 6) = $(Get-Date -f MM/dd/yyyy)
$Main.Cells.Item(3, 6) = $($DBName.Replace(".accdb",""))
$i = 6
ForEach ($W in $Work)
$DateFunction = "=IF (G$i = " + [char](34) +"Mitigated" + [char](34) + ", TODAY(), IF (G$i = " + [char](34) +"Escalated" + [char](34) + ", TODAY(), IF (G$i = " + [char](34) +"Offline"", TODAY(), " + [char](34) +")))"
$Main.Cells.Item($i, 1) = $W.Workstation
$Main.Cells.Item($i, 2) = $W.VulnCount
$Main.Cells.Item($i, 3) = $W.OS
$Main.Cells.Item($i, 4) = $W.AuditID
$Main.Cells.Item($i, 5) = $W.Name
$Main.Cells.Item($i, 6) = $W.Fix
$Main.Cells.Item($i, 7) = "Open"
$Main.Cells.Item($i, 9) = $DateFunction
$TBString = "{0},{1}" -f $W.Workstation, $W.AuditID
$Main.Cells.Item($i, 12) = $TBString
$i++
$ActiveWorkbook.SaveAs($NewFile)
$ExcelObject.Quit() | Out-Null
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ExcelObject)
Stop-Process -Id $ExcelId -Force -ErrorAction SilentlyContinue
If someone can help me figure out how to add this custom excel function. When I run the function everything gets filled out but the date function.

Try this instead:
$DateFunction = "=IF (G$i = `"Mitigated`", TODAY(), IF (G$i = `"Escalated`", TODAY(), IF (G$i = `"Offline`", TODAY(), `"`")))"
You can just escape the " with a backtick ` you don't need + [char](34) +
You were also missing a double-quote at the end of the formula which is probably what was causing the problem.
I hope this post has helped!

Similar Messages

  • Help writing a excel macro to do a copy of 4 cells and paste transpose. I need to loop the copy and paste through 6900 rows of data.

      I need help writing a excelmacro to do a copy of 4 cells and paste transpose.  I need to loop the copy and paste through 6900 rows of data.  I started the macro with two rounds of copying & paster transposed but I need help getting it
    to loop through all rows.  Here is what macro looks like now.
        Range("I2:I5").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("J2").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
        Range("I6:I9").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("J6").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
    End Sub

    Thanks Jim for the solution above.
    Hi Brogents,
    Thanks for posting in our forum. Please note that this forum focuses on questions and feedback for Microsoft Office client. For any
    VBA/Macro related issues, I would suggest you to post in the forum of
    Excel for Developers, where you can get more experienced responses:
    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Need help on OLE excel paste in selected cell range

    Hi Friends,
    I need to paste the clipbord contents in a selected range of cells using ole automation.
    Rage is selected using the following code :
    CALL METHOD OF G_EXCEL 'Cells' = G_CELL1
        EXPORTING #1 = 4
        #2 = 1.
      CALL METHOD OF G_EXCEL 'Cells' = G_CELL2
        EXPORTING #1 = P_ROW
        #2 = gv_col.
      CALL METHOD OF G_EXCEL 'Range' = G_CELLRANGE
        EXPORTING #1 = G_CELL1
        #2 = G_CELL2.
    now need to past the clipbord contents in G_CELLRANGE.
    Would appriciate your help,
    Thanks,
    John

    Hi Jhon,
    this is the obsolete old way even Rich would not recommend (look at the age of the blog).
    There are far better and much more performat ways doing this using Desktop Office Integration.
    Refer to this complete documentation of [Desktop Office Integration (BC-CI)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf]
    It took me some time to create my first application with DOI, but if you have done you will never want to miss it.
    Regards,
    Clemens

  • Excel Function to query BW using Web Services API

    Hello,
    I need to write an Excel function as an .XLA that will do the following:
    It will be invoked like any other Excel function. E.g. =GetCost(param p1, param p2)
    This function queries an InfoCube and must return a single numerical value for the Cell in Excel that the function is used in.
    I have never done anything like this before. I have done a decent amount of reading to discover the best way to attack this. It seems like the best way to create this functionality is to:
    1. create a web service in a BW function group with a function module that is RFC enabled.
    2. I'm thinking the function module will use native SQL to query the InfoCube and pull the value and then somehow pass this value to a web service.
    3. The value in the web service will be accessed through it's API in Excel/VBA.
    I am not sure if this is best way to do this, or if it is even possible to do it this way. I was wondering if anyone could tell me if I am heading down the right path and possibly direct me to a tutorial or other information that would aid in accomplishing this. I have yet to find some type of proof of concept from beginning to end on how to do something like this. Any help would be greatly appreciated.
    These are the documents I have found insightful so far:
    How to build an XLA: http://www.fontstuff.com/vba/vbatut03.htm
    If you can read a table and dump it into Excel then you can query an InfoCube? https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c043d836-166c-2910-b99e-ae3633dec547
    How to view a webservice homepage: http://help.sap.com/saphelp_nw04/helpdata/en/1c/472e22c45cc94599ab3725bc9558d2/content.htm
    How to create a webservice:
    http://help.sap.com/saphelp_nw04/helpdata/en/9b/dad1ae3908ee44a5caf57e10918be9/frameset.htm
    What I am missing is how to pass data from the function module to the webservice, and from the webservice to the Excel/VBA code.
    Thanks!
    -Gary

    /bump

  • To export pivot table from excel and save as picture using powershell

    I am trying to automate my work by attaching an excel file to email and send it across using powershell . But also, I want to paste the screenshot of  pivot table to my email body .
    One way to do it is to save only the pivot table as picture format like jpeg or png , then attach this picture to the email body .
    I am looking for an powershell script which will save my pivot table as picture format . I am using powershell V1.0
    please help .

    I'm not familiar with PowerShell script, we usually use VBA script within excel.
    The following article describes how to export Excel Range to a Picture File and attach it as the email body by VBA code, it might not be the answer you are looking for, but hope it will give you some inspirations.
    http://www.jpsoftwaretech.com/export-excel-range-to-a-picture-file/
    Also you can post your question to PowerShell forum to get better support.
    Best Regards,
    Wind Zhang

  • Need some help with a remove function

    Design and code a program that will maintain a list of product names. Use a String type to represent the product name and an array of strings to implement the list. Your program must implement the following methods:
    Add a product to the list
    Remove a product from the list
    Display then entire list
    Find out if a particular product is on the list.
    You need to create a command command loop with a menu() function. The program must continue asking for input until the user stops.
    This is the assignment and this is what I have so far. I need some help writing the remove function.
    Thanks
    * Title: SimpleSearchableList.java
    * Description: this example will show a reasonably efficient and
    * simple algorithm for rearranging the value in an array
    * in ascending order.
    public class SimpleSearchableList {
         private static String[] List = new String[25]; //These variables (field variables)
         private static int Size; //are common to the entire class, but unavailable
         //except to the methods of the class...
         public static void main(String[] args)
              String Cmd;
              for(;;) {
                   Menu();
                   System.out.print("Command: ");
                   Cmd = SimpleIO.inputString();
                   if(Cmd.equals("Quit"))
                        break;
                   else if(Cmd.equals("Fill"))
                        FillList();
                   else if(Cmd.equals("Search"))
                        SearchList();
                   else if(Cmd.equals("Show"))
                        ShowList();
                   else if(Cmd.equals("Remove"))
                        Remove();
         //Tells you what you can do...
         public static void Menu()
              System.out.println("Choices..................................");
              System.out.println("\tFill to Enter Product");
              System.out.println("\tShow to Show Products");
              System.out.println("\tSearch to Search for Product");
              System.out.println("\tRemove a Product");
              System.out.println("\tQuit");
              System.out.println(".........................................");
         //This method will allow the user to fill an array with values...
         public static void FillList()
              int Count;
              System.out.println("Type Stop to Stop");
              for(Count = 0 ; Count < List.length ; Count++)
                   System.out.print("Enter Product: ");
                   List[Count] = SimpleIO.inputString();
                   if(List[Count].equals("Stop"))
                        break;
              Size = Count;
         //This method will rearrange the values in the array so that
         // go from smallest to largest (ascending) order...
         public static void SearchList()
              String KeyValue;
              boolean NotFoundFlag;
              int Z;
              System.out.println("Enter Product Names Below, Stop To Quit");
              while(true)
                   System.out.print("Enter: ");
                   KeyValue = SimpleIO.inputString();
                   if(KeyValue.equals("Stop")) //Note the use of a method for testing
                        break; // for equality...
                   NotFoundFlag = true; //We'll assume the negative
                   for(Z = 0 ; Z < Size ; Z++)
                        if(List[Z].equals(KeyValue)) {
                             NotFoundFlag = false; //If we fine the name, we'll reset the flag
              System.out.println(List[Z] + " was found");
                   if(NotFoundFlag)
                        System.out.println(KeyValue + " was not found");     
         //This method will display the contents of the array...
         public static void ShowList()
              int Z;
              for(Z = 0 ; Z < Size ; Z++)
                   System.out.println("Product " + (Z+1) + " = " + List[Z]);
         public static void Remove()
    }

    I need help removing a product from the arrayYes. So what's your problem?
    "Doctor, I need help."
    "What's wrong?"
    "I need help!"
    Great.
    By the way, you can't remove anything from an array. You'll have to copy the remaining stuff into a new one, or maybe maintain a list of "empty" slots. Or null the slots and handle that. The first way will be the easiest though.

  • Cfspeadsheet not picking up data from cells using excel function indirect

    I am receiving data from comany executive in a sreadsheet and trying to post selected data to a company intranet by reading the data using cfspreadsheet.  for the most part, cfspeadsheet works, however, this speadsheet is rather complicated.  The spreadsheet uses the excel indirect function to determine which data to post.  When I read this cell, or any cell dependent on it, with SpreadsheetGetCellValue, if get the cell formula instead or the calculated value for the cell.  Is this function not supported by cold fusion?
    Is there any way around this?
    Is the a list somewhere of which Excel functions are or are not supported?

    Thanks for your reply...
    it is now displaying data in independent cells , but is it possible to add multiple headings in that excel sheet.
    ex
    Heading 1
    heading 2
    Column Headings-------
    Is it possible to do that way?? for column headings i think we need to pass in fields parameter of Tables...
    can we include multiple headings???
    Thanks for help..

  • Does Numbers support Excel functions CELL, SUBSTITUTE, and REDIRECT?

    Been trying to find the list of Excel-compatible functions but did not succeed. I would like to use Numbers to edit my Excel files in iPad. I often generate reports by pulling data out from a seperate sheet using Excel functions like CELL, SUBSTITUTE, and REDIRECT. I have not purchased Numbers yet, that is why I would like to know where I find the complete list of Excel-compatible functions or at least know if Numbers support these functions.  Thank you in advance.

    Numbers does support the function substitute()
    I did not see the functions cell() and redirect() in the function browser.
    There is afree function reference here:
    iWork '09 Formulas and Functions User Guide
    which you can use

  • Help: writing large data to excel using java

    Hi All
    I had a question writing a 6000 rows of data with 20 colums to a excel sheet. I am using Apache POI
    When we are writing some data to a file we store the data in an stringbuffer and then write the data to the file all at once.
    Is the same possible with excel? if so how?
    And what is the best way of wring data to an EXCEL file considering the above data into consideration.
    Please guide me thanks in advance.
    Regards
    Diana

    Text Files and Excel formatted files treat things differently--basically no, you cannot group multiple fields into one string: Excel has the concept of cells that you need to write the data into and will act similar to fields in a DB. On the other hand, you can drop the Excel formatting and write CSV files and Excel will load them just fine. With a CSV file you can write it all to a String, StringBuffer, StringBuilder or what ever String type of object you want and write an entire line at a time.

  • Best practises for using Excel functions on Power Pivot Data

    Hi
    How do you suggest to perform calculations on cells in a power pivot table? Obviously the ideal approach is to use a DAX measure. But given that DAX doesn't have every function, is there a recommended way of eg adding an "extra"  ( ie just
    adjacent)  column to a pivot table. ( in particular I want to use beta.inv )  
    I could imagine one option of adding some VBA that would update the extra column as the pivot table itself refreshed ( and added more/less rows)
    thanks
    sean

    Hi Sean,
    I don't know what's your expected requirement regarding this issue, maybe you can share some sample data or scenario to us for further investigation. As we know, if we need to add extra column to PowerPivot data model, we can directly
    create a calcuated column:
    calculated columns:
    http://www.powerpivot-info.com/post/178-how-to-add-dax-calculations-to-the-powerpivot-workbooks
    There are some different between Excel and DAX functions, here are the list for your reference:
    Excel functions (by category):
    http://office.microsoft.com/en-us/excel-help/excel-functions-by-category-HA102752955.aspx
    DAX Function Reference:
    http://msdn.microsoft.com/en-us/library/ee634396.aspx
    Hope this helps.
    Regards, 
    Elvis Long
    TechNet Community Support

  • Adding "Filter Criteria" to the XSLT List View Web Part impact on "Export to Excel" functionality within Document Library

    Hi there,
    XSLT List View displaying all the list items within the Document Library. In order to implement the Search functionality within Document library out of box "Text Filter" web part is configured as explained below. The solution is similar to
    the one suggested at
    http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=77
    "Text Filter" Web Part added to the page.
    Filter Criteria (i.e., XSLT List View columns) added to the XSLT List View where the filter parameters take the input from the "Text Filter" Web Part .
      3. Both Web Parts (XSLT List View and the Text Filter) are connected.
    When the search criteria is entered into the "Text Filter" Web Part, it is passed to the relevant Columns of the XSLT List View and the documents (List Items) that match the search criteria are shown within XSLT List View.
    Search functionality working as expected.
    Query: Selecting the "Export to Excel" icon from the ribbon generates the excel spread sheet with no data except Column Titles from the Document library. In the investigation it is
    found that adding the 'Filter Criteria' on XSLT List View is causing this bug. When the Filter Criteria is removed, then "Export to Excel" functionality is working as expected.
    But it is mandatory to add "Filter Criteria" to implement the search functionality with in the document library.
    Help: Help/input appreciated on the work around to get the "Export to Excel" functionality work when the "Filter Criteria"
    exist on the XSLT List View.
    Regards,

    Once again thanks very much for your help Scott. very much appreciated.
    In the investigation it is found that removing the 'Filter Criteria' on XSLT List View makes the "Export to Excel" functionality work. But the 'Filter Criteria' is mandatory to get the 'Document Search' functionality.
    I think that due to technical limitations it should be concluded that 'only custom development can make all work, no code solutions using the SharePoint Designer can meet all the requirements.
    If you can think of any alternative solution that could help in resolving the current issue or fix the issue without any custom implementation please inform. Otherwise this issue would be marked as resolved with your suggested response.
    Regards,

  • Help Required :Excel Upload Into Oracle Table Using PLSQL Procedure/Package

    Please Help , Urgent Help Needed.
    Requirement is to Upload Excel file Into Oracle Table Using PLSQL Procedure/Package.
    Case's are :
    1. Excel File is On Users/ Client PC.
    2. Application is on Remote Server(Oracle Forms D2k).
    3. User Is Using Application Using Terminal Server LogIn.
    4. So If User Will Use to GET_FILE_NAME() function of D2K to Get Excel File , D2k Will Try to pick File from That Remote Server(Bcs User Logind from Terminal Server Option).
    5. Cannot Use Util_File Package Or Oracle Directory to Place That File on Server.
    6. we are Using Oracle 8.7
    So Need Some PL/SQL Package or Fuction/ Procedure to Upload Excel file on User's Pc to Oracle Table.
    Please Guide me wd some Code. or with Some Pl/SQL Package, or With SOme Hint. Or any Link ....
    Jus help to Sort This Issue ........
    you can also write me on :
    [email protected], [email protected]

    I also Tried to Use This
    But How can i Use SQLLDR Command In Stored Procedure.
    Well IN SQL*PlUS it is successfull but in Stored Procedure /Package ,PL/SQL does not recognise the OS commands.
    So now my Question How can I recognise the SQLLDR Commnad in Stored Procedure.

  • Help Required:How Upload Excel file Into Oracle Table Using PLSQL Procedure

    Please Help , Urgent Help Needed.
    Requirement is to Upload Excel file Into Oracle Table Using PLSQL Procedure/Package.
    Case's are :
    1. Excel File is On Users/ Client PC.
    2. Application is on Remote Server(Oracle Forms D2k).
    3. User Is Using Application Using Terminal Server LogIn.
    4. So If User Will Use to GET_FILE_NAME() function of D2K to Get Excel File , D2k Will Try to pick File from That Remote Server(Bcs User Logind from Terminal Server Option).
    5. Cannot Use Util_File Package Or Oracle Directory to Place That File on Server.
    6. we are Using Oracle 8.7
    So Need Some PL/SQL Package or Fuction/ Procedure to Upload Excel file on User's Pc to Oracle Table.
    Please Guide me wd some Code. or with Some Pl/SQL Package, or With SOme Hint. Or any Link ....
    Jus help to Sort This Issue ........
    you can also write me on :
    [email protected], [email protected]

    TEXT_IO is a PL/SQL package available only in Forms (you'll want to post in the Forms forum for more information). It is not available in a stored procedure in the database (where the equivalent package is UTL_FILE).
    If the Terminal Server machine and the database machine do not have access to the file system on the client machine, no application running on either machine will have access to the file. Barring exceptional setups (like the FTP server on the client machine), your applications are not going to have more access to the client machine than the operating system does.
    If you map the client drives from the Terminal Server box, there is the potential for your Forms application to access those files. If you want the files to be accessible to a stored procedure in the database, you'll need to move the files somewhere the database can access them.
    Justin

  • Create a check box in excel cell  using sap abap

    Dear Sap Master's,
    Please give me some idea on  how to create a check box in excel cell using abap program..
    (OLE concept).
    Thanks
    Moderator message: please search for available information first.
    Edited by: Thomas Zloch on Jan 12, 2012

    select the cell then open the cell formatter:
    process should be similar in the iOS version.  I do not have any iOS devices with Numbers so I cannot check.  I did find this link that may help:
    http://support.apple.com/kb/PH3374?viewlocale=en_US

  • Excel 2013 not switching cells with cursor keys

    Hello
    I am currently having trouble with excel 2013 x64
    When i use the cursor keys like in earlier versions of excel, instead of navigating through cells, the whole sheet scrolls by that cell in one direction. I am not sure if I have changed the settings or not and any help making it work like older versions
    of excel and the 32 bit edeition.
    Thank you

    Maybe you have accidentally pressed the Scroll Lock key (sometimes the key says ScrLk. Most keyboards have a light to indicate that Scroll Lock is on. Pressing the key again turns it off.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

Maybe you are looking for

  • "Invalid Oracle Home directory" error in Application Server Connection

    I have Jdeveloper 10g on Windows XP and want to create an Application Server Connection. After specifying required i get Test failed (-2). Invalid Oracle Home directory whenever I go for testing it. My Application Server in Linux

  • Whose Transmission Tower is Better?

    So you think that Verizon is any better than AT&T or AT&T is any better than Verizon take a look at this... Bloomberg Financial News 7/21/08 SBA Communications, the mobile-phone tower operator for both AT&T and Verizon Wireless, agreed to buy Optasit

  • Accidentaly clicked on full screen, how do I go back to regular size screen?

    Have full screen and can not go back to regular size screen. There is no task/tool bar in full screen. Can't even get back to desktop.

  • Call the Function "Import Items" of Inventory Module by a external java app

    I want call the Import Items Function of inventory from my java application. This function copy the Items from MTL_SYSTEM_ITEMS_INTERFACE into the table that inventory use to manage the Items. Do you know how can I do? Thanks Gabriele

  • Select into from 2 tables

    Thanks in advance Is it possible do a SELECT INTO from 2 tables, that is (like in Informix) declare rg_table1    table1%ROWTYPE; rg_table2    table2%ROWTYPE; BEGIN              SELECT A.*, B.* INTO  rg_table1 , rg_table2