Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Opening excel spreadsheet from within a VBscript

I need to open an excel spreadsheet from within a
VBscript and then run a macro within that spreadsheet
before closing it back down again.
Can anyone provide some code that would do this.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening excel spreadsheet from within a VBscript

DISCO.

Try

Set xl = CreateObject("Excel.application")

xl.Application.Workbooks.Open "yourworkbookpath\yourworkbook.xls"
xl.Application.Visible = True
xl.Application.run "'yourworkbookname.xls'!macronametorun"

Set xl = Nothing


This should do exactly what you need.

HTH


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening excel spreadsheet from within a VBscript

Just an extra note to the last post.

Make sure that you add the code to close the workbook and application
in the excel sheet macro so that the focus is then returned to the rest
of your vbscript.

I normally use
ActiveWorkbook.Save
Application.Quit

HTH


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening excel spreadsheet from within a VBscript

Hi,
This code helps but I now have the problem that the
workbook I am closing is asking if I would like to save
the changes that have been made by the macro.
The answer is no but I'm not sure how to put this into
the code.
Do you know how i can do this ??

Thanks


-----Original Message-----
Just an extra note to the last post.

Make sure that you add the code to close the workbook

and application
in the excel sheet macro so that the focus is then

returned to the rest
of your vbscript.

I normally use
ActiveWorkbook.Save
Application.Quit

HTH


---
Message posted from http://www.ExcelForum.com/

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening excel spreadsheet from within a VBscript

you can use the
application.displayalerts = false
that will make excel use defualts instead of ask you what you want to
do. If you do not want it to save the sheet then do
xl.close false


Hope that helps.

Keith
www.kjtfs.com


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening excel spreadsheet from within a VBscript

Disco,

You can get round this by using

ActiveWorkbook.Close False

' closes the active workbook without saving any changes


instead of

activeworkbook.save


HT

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Opening excel spreadsheet from within a VBscript

I assume you really mean VBScript and not VBA, so here goes;

Here is a sample VBScript. Save it in a standard text file with a .VBS
extention.
This one creates an Excel object, opens a workbook, sets a value, runs a VBA
routine, then tides up and closes down.

Set xlObj = CreateObject("Excel.application")
xlObj.Workbooks.Open "C:\Byg\textfile\TextFileReformat.xls"
xlObj.Range("NoOfCharsPerLine").Value = 50
xlObj.Run "ReadFromTextFile"
xlObj.ActiveWorkbook.Saved = True
xlObj.ActiveWindow.Close
xlObj.Quit


--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"



"Disco" wrote in message
...
I need to open an excel spreadsheet from within a
VBscript and then run a macro within that spreadsheet
before closing it back down again.
Can anyone provide some code that would do this.

Thanks



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening excel spreadsheet from within a VBscript

Andy wrote:
[b]I assume you really mean VBScript and not VBA, so here goes;

Here is a sample VBScript. Save it in a standard text file with a
.VBS
extention.
This one creates an Excel object, opens a workbook, sets a value,
runs a VBA
routine, then tides up and closes down.

Set xlObj = CreateObject("Excel.application")
xlObj.Workbooks.Open "C:\Byg\textfile\TextFileReformat.xls"
xlObj.Range("NoOfCharsPerLine").Value = 50
xlObj.Run "ReadFromTextFile"
xlObj.ActiveWorkbook.Saved = True
xlObj.ActiveWindow.Close
xlObj.Quit


[b]

Don't forget to
Set xlObj = Nothing

at the end......

Keith
www.kjtfs.com



---
Message posted from http://www.ExcelForum.com/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening more than 1 Excel Spreadsheet Catlady Excel Discussion (Misc queries) 4 March 2nd 07 11:49 PM
Can i include a vbscript file with an xml spreadsheet? Neil.Wills Excel Discussion (Misc queries) 0 September 1st 05 12:34 AM
Opening Excel spreadsheet in MAC Doug Excel Discussion (Misc queries) 2 June 26th 05 12:34 AM
Opening an excel spreadsheet Frustrated Excel Worksheet Functions 1 April 2nd 05 06:39 PM
VBScript Automation of Excel Spreadsheet Sorting & Filtering Tom Ogilvy Excel Programming 1 September 10th 03 03:01 PM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"