Hi all,
I'm writing a small application that allows the user to pick a .csv file that is outputted via a 3rd party app that records blood pressure, and then takes the .csv and carries out some formatting and average/countif calculations.
If I open the .CSV by hand as well as the .xlsb file that contains the macro and run it using excel, it runs fine however, when using the below code to automate this, the output is not as would be expected (i.e. some formatting not carried out and some rows not deleted as the macro dictates;
I'm writing a small application that allows the user to pick a .csv file that is outputted via a 3rd party app that records blood pressure, and then takes the .csv and carries out some formatting and average/countif calculations.
If I open the .CSV by hand as well as the .xlsb file that contains the macro and run it using excel, it runs fine however, when using the below code to automate this, the output is not as would be expected (i.e. some formatting not carried out and some rows not deleted as the macro dictates;
Code:
Imports Excel = Microsoft.Office.Interop.Excel
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBooks = oExcel.Workbooks
'opens the file already selected, the location for which is currently in textbox2
oBook = oBooks.Open(TextBox2.Text)
'Run the macros.
oExcel.Run("'C:\Omron Healthcare\Omron Health Management Software\System\OmronReport.xlsb'!BP_Macro")
'Clean-up: Close the workbook and quit Excel.
oBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
End Sub