VBSsript delete column in current Excel sheet
Moderators: Dorian (MJT support), JRL
VBSsript delete column in current Excel sheet
Hello !!!
Please, can you give me an example of VBScript delete specific column in current open Excel sheet ?
Thanks and greetings,
Reimon
Please, can you give me an example of VBScript delete specific column in current open Excel sheet ?
Thanks and greetings,
Reimon
Most of the following is blatantly plagiarized from Marcus' Blog Article.
Methods for Accessing Excel Data
I came up with the "DelCol" function
Methods for Accessing Excel Data
I came up with the "DelCol" function
Code: Select all
Let>ExcelFile=C:\test.xls
//Put this VBSTART..VBEND block at top of script
//to declare the functions once
VBSTART
Dim xlApp
Dim xlBook
'Opens the Excel file in Excel
Sub OpenExcelFile(filename)
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = true
Set xlBook = xlApp.Workbooks.open(filename)
end sub
'Use this to close Excel later
Sub CloseExcel
xlApp.quit
Set xlApp = Nothing
End Sub
'Retrieves a cell value from the specified
'worksheet
Function GetCell(Sheet,Row,Column)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
GetCell = xlSheet.Cells(Row, Column).Value
End Function
'Sets specified cell of specified worksheet
Function SetCell(Sheet,Row,Column,NewValue)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
xlSheet.Cells(Row,Column).Value = NewValue
End Function
Function DelCol(Sheet,Col)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
xlSheet.range(Col).Delete
End Function
VBEND
//Do the business
VBRun>OpenExcelFile,ExcelFile
VBEval>GetCell("Sheet1",5,4),theValue
//MessageModal>Cell value: %thevalue%
//VBEval>SetCell("Sheet1",28,2,998),nul
//Will delete column B
//To delete a range of columns, change to "B:E" for example
VBEval>DelCol("Sheet1","B:B"),nul
//VBRun>CloseExcel
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
There was nothing on the "DelCol" function because the "DelCol" function is a function that JRL just created! I couldn't write about something that someone else in the future was some day going to create.
JRL has created you a function that calls Excel's Delete method (App->Book-Sheet->Range->Delete)
If you record a macro inside Excel and delete a column, then view the source of the macro you will see very similar code created by Excel.
Then take a look at this blog post to get an idea of how to translate that code into VBScript which you can run inside Macro Scheduler:
http://www.mjtnet.com/blog/2008/04/28/c ... -vbscript/
JRL has created you a function that calls Excel's Delete method (App->Book-Sheet->Range->Delete)
If you record a macro inside Excel and delete a column, then view the source of the macro you will see very similar code created by Excel.
Then take a look at this blog post to get an idea of how to translate that code into VBScript which you can run inside Macro Scheduler:
http://www.mjtnet.com/blog/2008/04/28/c ... -vbscript/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Set newXMLbook = xlApp.WorkBooks.OpenXML("c:\temp.xml", , 2)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?