3

My application is generating a csv file that I want to move to another directory when user clicks export button.

My VBScript code is:

Sub ExportTocsv()
    Dim oDLG
    Set fso  = CreateObject("Scripting.FileSystemObject")
    Set oDLG=CreateObject("MSComDlg.CommonDialog")  
    Set file = fso.OpenTextFile("results.csv", 1)
        text = file.ReadAll
        file.Close

    With oDLG
        .DialogTitle="SaveAs"
        .Filter="Comma Separated Version|*.csv;|Text Files|*.txt|All files|*.*"
        .MaxFileSize=255
        .ShowSave
        If .FileName<>"" Then
            FileName=.FileName
            Set objOutFile = fso.CreateTextFile(FileName,True)
            objOutFile.write(text)
            objOutFile.close
        End If
    End With
    Set oDLG=Nothing
End Sub

It gives me an error message "ActiveX component can't create object". What is solution or workaround for this?

I can't install anything in my environment.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Kailash Singh
  • 405
  • 2
  • 7
  • 12
  • 1
    `VBScript` <> `VB.NET`. – Visual Vincent Mar 29 '16 at 08:21
  • This guy had the same problem, see if the answer'll help: [MSDN Forum](https://social.technet.microsoft.com/Forums/scriptcenter/en-US/0511c9d4-9e92-4f2c-baf7-5428d3b2d44c/unable-to-create-a-filesystemobject-in-vbscript?forum=ITCG). Or this one: [Stack Overflow](http://stackoverflow.com/q/5457000/3740093). – Visual Vincent Mar 29 '16 at 08:26
  • Yes similar issue..... Set oDLG=CreateObject("MSComDlg.CommonDialog") – Kailash Singh Mar 29 '16 at 08:42
  • Well you never pointed out which line was the problem, so I assumed that the `Scripting.FileSystemObject` was, as that is the first line. – Visual Vincent Mar 29 '16 at 08:54
  • 1
    This answer has several solutions: http://stackoverflow.com/a/24395498/3740093 - The problem seems to appear if you do not have the `comdlg32.dll` registered in your registry. I believe you get this file when installing for example Visual Studio, however the answerer has also given a link to where you can download it. – Visual Vincent Mar 29 '16 at 09:02

0 Answers0