Content Management and Capture

 View Only
  • 1.  vbscript create Excel Object inside custom action

    Posted Thu January 25, 2024 05:06 PM

    I need to be able to create an Excel file inside of a custom action in our custom.rrx vbscript file.  Excel is installed on the rulerunner server that needs to create the file.  I have a code blurb below that works perfectly if I put it in a vbs file and run it manually on the server.  If I do it inside my custom action nothing happens and there is no error written to the log.  How can I create an excel file inside my action?

    Dim objExcel, ExcelFilePath
    ExcelFilePath = "D:\DataCap\ExcelTest\EXCEL_FILE.xlsx"
    ExcelFilePath2 = "D:\DataCap\ExcelTest\ExcelFileNew.xlsx"
     
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objExcel = CreateObject("Excel.Application")
     
    If objFso.FileExists(ExcelFilePath) Then
    objExcel.Workbooks.Open(ExcelFilePath)
    objExcel.Worksheets(1).Cells(1,1) = "Hello UFT"
    objExcel.ActiveWorkbook.Save
    Else
    objExcel.Workbooks.Add
    objExcel.Worksheets(1).Cells(1,1) = "Hello UFT"
    objExcel.ActiveWorkbook.SaveAs(ExcelFilePath2)
    End If
     
    objExcel.Quit
    Set objExcel = Nothing


    ------------------------------
    Danny Mann
    ------------------------------


  • 2.  RE: vbscript create Excel Object inside custom action

    Posted Fri January 26, 2024 12:41 PM

    Here are a few items to consider…

    • Is the custom action running under credentials that have access to write to your output folder?
    • Have you tried adding error handling and logging to your script to get more insight into the error?
    • If a CSV is acceptable in lieu of an XLS, you might review the CSV actions under the ExportToText library (although a custom action is probably a better option here)

    Good luck,

    Robert Stegall



    ------------------------------
    Robert Stegall
    ------------------------------



  • 3.  RE: vbscript create Excel Object inside custom action

    Posted Fri January 26, 2024 02:05 PM

    The custom action has permission to do everything it is doing.  If I log in as the rulerunner user and execute this code manually in a stand-along file outside of Datacap it runs great.  

    I have the Datacap logging turned up all the way and that is where I usually see any errors that occur.

    Unfortiunately I have to create this in an excel format.  They do not want a csv for some reason



    ------------------------------
    Danny Mann
    ------------------------------



  • 4.  RE: vbscript create Excel Object inside custom action

    Posted Fri January 26, 2024 02:52 PM

    I think you are really going to need to add error-handling and logging statements in your code to get the detailed information on the error.  There is nothing capturing that data now (Datacap won't magically do it on its own).

    To see some examples of this code, you can drop a 'compiled' VBScript into Notepad++ or similiar.  Scroll down past the header junk and you'll get to the scripts implementing the action logic.  One example of this type of file is 'barcode_p.dll'.



    ------------------------------
    Robert Stegall
    ------------------------------



  • 5.  RE: vbscript create Excel Object inside custom action

    Posted Fri January 26, 2024 02:59 PM

    I added some error handling and did get one displayed:

    Error Occured: 1004 and description is: SaveAs method of Workbook class failed

    At least now I have somewhere to look.  The user definitely has permission to write to that location.  Any other ideas for what would cause that particular error?



    ------------------------------
    Danny Mann
    ------------------------------



  • 6.  RE: vbscript create Excel Object inside custom action

    Posted Mon January 29, 2024 01:44 AM

    Not other than the obvious ones, like a pre-existing file with that name or an invalid path.



    ------------------------------
    Robert Stegall
    ------------------------------