Thursday, December 19, 2013

Function to Copy data from an excel file into SIFPRO

Function To_copy_data_fromanexcelfile_intoSIFPRO(strFilePath1,strFilePath2)
Dim strFso
Dim objExcel
Dim objWorkbook1
Dim objWorkbook2
Dim objRange
Dim strFile1
Dim strFile2
To_copy_data_fromanexcelfile_intoSIFPRO = -1
Set strFso = CreateObject("Scripting.FileSystemObject")
If Not (strFso.FileExists(strFilePath1)) Then
Reporter.ReportEvent micDone,"Function Terminated","The specified file " & strFilePath1 & " does not exist"
Convert_Excen_File_Xls_To_Csv = -1
Exit Function
End if
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(strFilePath1)
Set objWorkbook2= objExcel.Workbooks.Open(strFilePath2)
objWorkbook1.Worksheets("Sheet1").UsedRange.Copy
objWorkbook2.Worksheets("Sheet 1").Range("A2").Pa
steSpecial Paste =xlValues
objWorkbook1.save
objWorkbook1.close
Set objRange = objExcel.Cells(2, 1).EntireRow
objRange.Delete
objWorkbook2.save
objWorkbook2.close
objExcel.Quit
set objExcel=nothing
If err.number = 0 Then
Convert_Excen_File_Xls_To_Csv = 0
End If
End Function

No comments:

Post a Comment