Write to empty cell in excel - InfoPath Dev
in

InfoPath Dev

Write to empty cell in excel

Last post 11-08-2006 06:18 AM by mbenbow. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 11-07-2006 08:34 AM

    Write to empty cell in excel

    Hi,

    I am a bit of a donkey with code, so could someone help me out. I would like to make infopath write the contents of a field into column A of an excel document when I hit a button. This excel file will grow as more infopath files write to it, so infopath would have to find an empty cell in column A to write to so as not to delete a previous entry.

    Thanks.
  • 11-08-2006 06:18 AM In reply to

    Re: Write to empty cell in excel

    Hey,

    Without knowing the complete details of how your project will be deployed, you might be able to use the following. It is written in VB Script: (Note: to use this code the form will need to be fully trusted - also, this code is off the top of my head and has not been tested.)

    Sub PopRowColValue(sFile, sToPop)

    'sFile - is the path to your excel file
    'sToPop - is the InfoPath field value to populate to Excel

    Dim objExcel
    Dim objActiveWorkbook
    Dim iAllRows
    Dim iLastRow
    Dim iRow
    Dim iCol


    Set objExcel = CreateObject("Excel.Application")
    Set objActiveWorkbook = objExcel.Workbooks.Open(sFile)

    'grab all the rows of the appropriate sheet
    iAllRows = objActiveWorkbook.WorkSheets("Sheet1").Rows.Count

    'set to column A
    iCol = 1

    For iRow = 0 to iAllRows
    If objActiveWorkbook.WorkSheets("Sheet1").Cells(iRow, iCol).Value = "" Then
    'tag it because it is the last row for the column
    iLastRow = iRow + 1
    Exit For
    End If
    Next

    'write it to excel
    objActiveWorkbook.WorkSheets("Sheet1").Cells(iLastRow, iCol).Value = sToPop


    End Sub
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.