I wrote a macro script which will upload excel data into orcale database also it generate excel sheet in othet location and its working fine, but whenever i run the macro it will take all rows from excel sheet and updated database so i am getting same data again and again.
Please can any one help me how to update only changed rows from excel to database.
Below is my code:
Thanks in Advance
Teja
Please can any one help me how to update only changed rows from excel to database.
Below is my code:
Code:
Sub AppendOracleTable() 'Create and set login information variables Dim logon As String Let logon = "scott" Dim password As String Let password = "tiger" 'Set Variables for Upload Dim Cust_id As String Dim Cust_Name As String Dim Product As String Dim Order_No As String Dim Wkb2 As Workbook ' Specify the location from which excel file loading, open the workbook you are copying from and activate it Set Wkb2 = Workbooks.Open(Filename:="C:\Documents and Settings\admin\Desktop\Excel__Macro\Input_File.xls") Wkb2.Activate 'Create and Set Session / Create Dynaset = Column Names Dim OraSession As Object Set OraSession = CreateObject("OracleInProcServer.XOraSession") Dim Host_name As String Host_name = "orcl" Dim OraDatabase As Object Set OraDatabase = OraSession.OpenDatabase("" & Host_name & "", "" & logon & " / " & password & "", 0&) Dim Oradynaset As Object Set Oradynaset = OraDatabase.DBCreateDynaset("SELECT * FROM Cust_tab", 0&) Range("A2").Select Do Until Selection.Value = "" Cust_id = Selection.Value Cust_Name = Selection.Offset(0, 1).Value Product = Selection.Offset(0, 2).Value Order_No = Selection.Offset(0, 3).Value Oradynaset.AddNew Oradynaset.Fields("Cust_id").Value = Cust_id Oradynaset.Fields("Cust_Name").Value = Cust_Name Oradynaset.Fields("Product").Value = Product Oradynaset.Fields("Order_No").Value = Order_No Oradynaset.Update Selection.Offset(1, 0).Select Loop Range("A1:D10").Select Selection.Copy Workbooks.Add ActiveSheet.Paste 'Range("D15").Select Application.CutCopyMode = False ' Location where we need to save new Excel sheet ActiveWorkbook.SaveAs Filename:= _ "C:\Documents and Settings\admin\Desktop\Excel__Macro\Output_File.xls", FileFormat:= _ xlNormal, password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False ActiveWindow.Close ActiveWindow.Close End Sub
Thanks in Advance
Teja
Comment