VBScript Error: Invalid procedure call or argument RRS feed

  • General discussion

  • I have the below code. I am getting an invalid call or procedure at this statement filetxt_Risk_Details.WriteLine(All_Record_Risk_Details).

    I am reading from the excel file and converting it into Risk_Details.csv file
    Can someone please tell me what's wrong with below script.

    = "Risk_No"&delimter&"Project_Number"&delimter&"Risk_Description"&delimter&"Risk_Owner"&delimter&"Risk_Management_Plan"&delimter&"Risk_Full_Impact_For_Open"&delimter&"Risk_Category" dim filesys_Risk_Details, filetxt_Risk_Details Set filesys_Risk_Details = CreateObject("Scripting.FileSystemObject") Set filetxt_Risk_Details = filesys_Risk_Details.OpenTextFile(Save_Projects_Risk_Details, ForWriting , True, True) filetxt_Risk_Details.WriteLine(Header_Risk_Details) c=24 Do While c < 300 Risk_No=Replace(objXLWs.Cells(c, "B").Text,vbLf,"<br>") Risk_Description=Replace(objXLWs.Cells(c, "C").Text,vbLf,"<br>") Risk_Owner=Replace(objXLWs.Cells(c, "D").Text,vbLf,"<br>") Risk_Management_Plan=Replace(objXLWs.Cells(c, "E").Text,vbLf,"<br>") Risk_Full_Impact_For_Open=Replace(objXLWs.Cells(c, "F").Text,vbLf,"<br>") if Risk_Description="Risk Description for Contractual Penalties (CP)" and Risk_Full_Impact_For_Open="Full Impact for open CP Risks" then Risk_Category="Risks Contractual Penalties" end if if Risk_Description="Risk Description for ALL OTHERS" and Risk_Full_Impact_For_Open="Full Impact for open Other Risks" then Risk_Category="Risks All Others" end if All_Record_Risk_Details= Risk_No&delimter&Project_Number&delimter&Risk_Description&delimter&Risk_Owner&delimter&Risk_Management_Plan&delimter&Risk_Full_Impact_For_Open&delimter&Risk_Category filetxt_Risk_Details.WriteLine(All_Record_Risk_Details) 'Error c = c + 1 Loop



    • Changed type Bill_Stewart Monday, January 7, 2019 8:31 PM
    • Moved by Bill_Stewart Monday, January 7, 2019 8:31 PM Unanswerable drive-by question
    Wednesday, November 14, 2018 7:17 PM

All replies

  • Ask the author of the script to fix it for you.

    This forum is for scripting questions rather than script requests

    -- Bill Stewart [Bill_Stewart]

    Wednesday, November 14, 2018 7:24 PM
  • To convert Excel to CSV just open the worksheet and save it as a CSV file.

    The code you have posted is not able to open Excel because there is no Excel object.

    Since you do not know how to script in VBS you should be using PowerShell.  Learning VBS is pointless as it is obsolete.

    See this for example of converting Excel to CSV: https://blogs.technet.microsoft.com/heyscriptingguy/2005/03/22/how-can-i-save-a-single-excel-worksheet-to-a-csv-file/


    Wednesday, November 14, 2018 7:26 PM
  • Did the header get written to the file? Were any records written to the file?

    Do something like this to verify that your variable contains data:

     debug.print "c=" & c & "   Length of All_Record_Risk_Details=" & len(All_Record_Risk_Details)
     filetxt_Risk_Details.WriteLine(All_Record_Risk_Details)  'Error

    Run the macro and check the debug output. 

    Wednesday, November 14, 2018 7:34 PM
  • The problem with the code is that it haws many bad syntaxes and is missing many pieces.  The code was copied and edited which likely caused all of the damage.

    The code does not create a CSV it is creating an HTML output.

    Most of the required code is missing.

    This forum is not a place to come and have code you have found fixed or custom modified. 


    • Edited by jrv Wednesday, November 14, 2018 7:51 PM
    Wednesday, November 14, 2018 7:46 PM
  • There is no data in the file
    Wednesday, November 14, 2018 8:15 PM
  • Bill, I am not asking for script request. I was asking for what is the reason for the error cause in my script.

    -I will ask myself to fix it, thank you 

    Wednesday, November 14, 2018 8:36 PM
  • Jrv, thank you for suggesting to me (what everyone knows) on opening the worksheet and converting it into CSV. 

    I didn't post the entire script (which I can do if you want to see 2302 lines of code)

    Thank you for telling the importance of Powershell (everyone knows that VBS is outdated, I am not talking about Powershell in my question, please look at the question next time you reply to it). 


    Wednesday, November 14, 2018 8:41 PM
  • What good is posting code that doesn't work.

    The code, as posted, cannot be run and there is no way for us to debug it.

    Setfiletxt_Risk_Details =filesys_Risk_Details.OpenTextFile(Save_Projects_Risk_Details,8 ,True)  ' for appending with create.


    Wednesday, November 14, 2018 9:51 PM
  • Set a breakpoint on the opentextfile statement.

    Set filetxt_Risk_Details = filesys_Risk_Details.OpenTextFile(Save_Projects_Risk_Details, ForWriting , True, True)

    Verify that Save_Projects_Risk_Details contains a valid file name and that you have access to the file. Step through the code and check to see that your variables contain valid data.

    Thursday, November 15, 2018 12:03 AM