Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any resources for VBScript with Excel?

Status
Not open for further replies.

matfishe

Technical User
Apr 2, 2011
4
0
0
Hi,

I have some experience with VBScript but not as much when I use it with Excel. I was just wondering if anyone would know of any books or sites that wounld have information on how to use VBScipt with Excel??

Thanks in advance!
 
Basically you can open Excel from VBScript and do whatever there using this piece of code:
Code:
Set Ex = CreateObject("Excel.Application")
With Ex 
   .Visible = False 'true
   .Workbooks.Open ("D:\MyPath\MyWorkbook.xls")  
   a = .Workbooks("MyWorkbook.xls").Sheets(1).Cells(1,1).Value
   .Workbooks("MyWorkbook.xls").Save
   .Workbooks("MyWorkbook.xls").Close
End With
  Ex.Quit
  Set Ex = Nothing 
MsgBox a
You can find Open session of Excel using this piece of code:
Code:
Set OpenEx = GetObject(,"Excel.application")
With OpenEx 
   .Workbooks.Open ("D:\MyPath\MyWorkbook.xls")  
   .Workbooks("MyWorkbook.xls").Sheets(1).Cells(1,1).Value = "x"
End With
  Set OpenEx = Nothing
Or calling an Excel procedure (Sub 'MyProc()'):
Code:
Set OpenEx = GetObject(,"Excel.application")
With OpenEx 
   .Run "'MyWorkbook.xls'!MyProc"
End With
  Set OpenEx = Nothing
What is inside 'With ... End With' is the equivalent of Excel Application...

I hope this helps a little...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top