VBScript query

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
orion1951
Newbie
Posts: 2
Joined: Sat May 31, 2014 1:19 pm

VBScript query

Post by orion1951 » Sun Jul 26, 2015 12:16 pm

Hi,

I'm trying to get the following to work:

It doesn't seem to like the line: objExcel.ActiveSheet.Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Is there something wrong with it?

Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = False
strWB = "C:\Test\admin make busy."
Set objWorkbook = objExcel.Workbooks.Open(strWB & "xls")
objExcel.ActiveSheet.Rows("1:7").Delete
objExcel.ActiveSheet.Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
objExcel.ActiveSheet.Columns("K").Delete
objExcel.ActiveSheet.Columns("I").Delete
objExcel.ActiveSheet.Columns("C:F").Delete
objExcel.ActiveWorkbook.Save
objExcel.Quit

Thx,

John

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: VBScript query

Post by hagchr » Sun Jul 26, 2015 1:27 pm

Hi, I modified it slightly, hope it helps.

Code: Select all

VBSTART

Sub Test
    Set objExcel = CreateObject("Excel.Application")
    xlCTB=4 'Constant for xlCellTypeBlanks = 4
    objExcel.DisplayAlerts = False
    strWB = "C:\Test\admin make busy."
    Set objWorkbook = objExcel.Workbooks.Open(strWB & "xls")
    objWorkbook.ActiveSheet.Rows("1:7").Delete
    on error resume next
    objWorkbook.ActiveSheet.Columns("D:D").SpecialCells(xlCTB).EntireRow.Delete    
    objWorkbook.ActiveSheet.Columns("K").Delete
    objWorkbook.ActiveSheet.Columns("I").Delete
    objWorkbook.ActiveSheet.Columns("C:F").Delete
    objWorkbook.Save
    objWorkbook.Close
End Sub

VBEND

VBRun>Test

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts