Automate Excel with VBScript

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Automate Excel with VBScript

Post by Marcus Tettmar » Fri Feb 21, 2003 12:00 am

Contributed By: Marcus Tettmar [email protected]
Submitted On: 21/02/03

VBSTART
Sub ExcelExample
Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

xlApp.visible = True
'optionally make the sheet visible
'xlSheet.Application.Visible = True
xlSheet.Cells(1,1).Value = "This is the column A, row 1"
'etc
xlSheet.SaveAs "C:\files\mysheet.xls"
xlApp.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
VBEND
VBRun>ExcelExample

doug4knfpu
Newbie
Posts: 2
Joined: Fri Jul 20, 2012 10:15 pm

Re: Automate Excel with VBScript

Post by doug4knfpu » Wed Jul 25, 2012 4:28 pm

mtettmar wrote:Contributed By: Marcus Tettmar [email protected]
Submitted On: 21/02/03

VBSTART
Sub ExcelExample
Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

xlApp.visible = True
'optionally make the sheet visible
'xlSheet.Application.Visible = True
xlSheet.Cells(1,1).Value = "This is the column A, row 1"
'etc
xlSheet.SaveAs "C:\files\mysheet.xls"
xlApp.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
VBEND
VBRun>ExcelExample
can you explain this a little better?

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jul 25, 2012 4:35 pm

Well, microsoft might be the best people to explain it. Which bit do you want help with? The Excel COM object reference is here:
http://msdn.microsoft.com/en-us/library ... s.80).aspx
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

doug4knfpu
Newbie
Posts: 2
Joined: Fri Jul 20, 2012 10:15 pm

Post by doug4knfpu » Thu Aug 02, 2012 7:24 pm

Thanks for the reply, I found my answer on microsoft.com

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