Results 1 to 2 of 2

Thread: WSH + VBscript + Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    2

    WSH + VBscript + Excel

    Hi,

    I'm trying to write a small script that will edit certain cells within an excel file.

    So far I have the script opening and closing the file, doing various other bits like logging and so forth.

    But the main part of the script is what I'm having problems with.

    Esentially I want it to search for a certain value in column 'd'
    If that value exists I then want it to delete the data in column 'f' from the same row.

    If that makes sense ?

    If someone could post some sample code, I would be most grateful.

    This is using VBScript btw, not VB itself.
    The marco code I get from Excel 2002 dosen't work directly, so I guess it's designed for VB.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    This one seems to work in vbs - actually tested it too!
    VB Code:
    1. Dim objXLAPP
    2. Dim intRowCounter
    3.  
    4. Set objXLAPP = createobject("Excel.Application")
    5. objXLAPP.displayalerts = false
    6. objXLAPP.Workbooks.Open "C:\TestFile.xls"
    7.  
    8.     For intRowCounter = 1 to objXLAPP.Workbooks(1).Worksheets(1).usedrange.rows.count
    9.         If (objXLAPP.Workbooks(1).Worksheets(1).Cells(intRowCounter, 4).value = "2") then
    10.             objXLAPP.Workbooks(1).Worksheets(1).Cells(intRowCounter, 6).value = ""
    11.         End If
    12.     Next
    13.  
    14. objXLAPP.Workbooks(1).save
    15. objXLAPP.Workbooks(1).close
    16.  
    17. objXLAPP.displayalerts = true
    18. Set objXLAPP  = Nothing
    19.  
    20. Msgbox "Done!"

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width