1 Reply Latest reply on Sep 24, 2002 3:57 PM by 271367

    OO4O and Excel

    271367
      I have looked at the Excel Sample that comes with the OO4O Installation. It works perfectly and so I wanted to use it in an Excel Spreadsheet that I have. I modified the code so that I would query for one column of information and I wanted that one column of information to be inserted into column AK. Now, when I run the macro, it doesn't work. It will select the column and clear it but it will not insert the code where I need it to. Here is the code:

      Sub EmpData()

      'Declare variables as objects
      Dim OraSession As Object
      Dim OraDatabase As Object
      Dim EmpDynaset As Object

      Dim flds() As Object
      Dim fldcount As Integer

      Set OraSession = CreateObject("OracleInProcServer.XOraSession")
      Set OraDatabase = OraSession.OpenDatabase("PKDEMO", "*****/*****",
      0&)
      Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME from CU",
      0&)

      Range("AK1:AK50").Select
      Selection.ClearContents

      'Declare and create an object for each column.
      'This will reduce objects references and speed
      'up your application.
      fldcount = EmpDynaset.Fields.Count
      ReDim flds(0 To fldcount - 1)
      For Colnum = 0 To fldcount - 1
      Set flds(Colnum) = EmpDynaset.Fields(Colnum)
      Next


      'Insert Column Headings
      For Colnum = 0 To EmpDynaset.Fields.Count - 1
      ActiveSheet.Cells(1, Colnum + 1) = flds(Colnum).Name
      Next

      'Display Data
      For Rownum = 2 To EmpDynaset.RecordCount + 1
      For Colnum = 0 To fldcount - 1
      ActiveSheet.Cells(Rownum, Colnum + 1) = flds(Colnum).Value
      Next
      EmpDynaset.DbMoveNext
      Next

      Range("AK1:AK1").Select

      End Sub

      Sub ClearData()
      Range("AK1:AK50").Select
      Selection.ClearContents
      Range("AK1:AK1").Select
      End Sub

      Can someone help me understand where I'm going wrong? Thanks, Jeremy
        • 1. re:OO4O and Excel
          271367
          Nevermind, I figured it out. Where you see: Colnum + 1, you can change the 1 to any number of rows you want to move over to insert into, so if you want to insert into AK, Colnum + 37, is what you'd code into the macro.