Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a .bat file that opens, pauses & closes MS Excel

I am a beginner programmer and have never created a .bat
file. Although I have "some" prior knowledge of VB.
I am in need of creating a bat file (or something
comparable) that I can put into Scheduler to run every
morning.

The idea is to open Excel (Excel is set up to open the
file automatically), pause for 30 seconds (an automatic
update happens during this time), save the file
(overwrite), and then close Excel.
I have not been successful finding switches for Excel
(start it, save and close). Any switches, examples or
ideas you can provide would be extremely helpful. Thanks,
Alexa

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Creating a .bat file that opens, pauses & closes MS Excel

Hi Alexa,

I would suggest doing all processing in the Excel workbook instead of trying
to control Excel via the command line.

To open an Excel workbook, you can just enter the full path/filename for the
file into your batch file.

In the Workbook_Open event subroutine for your workbook, you can call a
subroutine to do what you need to do. At the end of the subroutine, do
this:

ThisWorkbook.Save
Application.Quit

In order for this to work unattended, you'll either have to:

1) set your macro security to low (not recommended)

or

2) sign the workbook with selfcert.exe (available on the MS site somewhere)
so it will be trusted

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


alexa wrote:
I am a beginner programmer and have never created a .bat
file. Although I have "some" prior knowledge of VB.
I am in need of creating a bat file (or something
comparable) that I can put into Scheduler to run every
morning.

The idea is to open Excel (Excel is set up to open the
file automatically), pause for 30 seconds (an automatic
update happens during this time), save the file
(overwrite), and then close Excel.
I have not been successful finding switches for Excel
(start it, save and close). Any switches, examples or
ideas you can provide would be extremely helpful. Thanks,
Alexa


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Creating a .bat file that opens, pauses & closes MS Excel

Thanks Jake.

Is the subroutine created in Excel itself?

all of this (except for entering the full path/filename for the file
into the batch file) done in Excel itself?.

Thanks again.
Alexa




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Creating a .bat file that opens, pauses & closes MS Excel

Alexa,

Alexa Arnold wrote:
Is the subroutine created in Excel itself?


Yes, I would put the code in the workbook you are opening. The
Workbook_Open event subroutine goes in the ThisWorkbook class module
(double-click it to get to its code pane). It could then in turn call
another subroutine (placed in a standard module) that does all the
processing. When done, the sub would save the workbook and quit Excel.

all of this (except for entering the full path/filename for the file
into the batch file) done in Excel itself?.


Yes.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Creating a .bat file that opens, pauses & closes MS Excel

To add to Jake's advice........

You can use Windows Task Scheduler to start Excel with your workbook using the
fulpath\filename.

Self-cert.exe should be in your Office folder OR StartProgramsMicrosoft
OfficeMicrosoft ToolsDigital Certificates for VBA Projects.

Gord Dibben Excel MVP

On Thu, 29 Apr 2004 15:34:15 -0700, "Jake Marx" wrote:

Hi Alexa,

I would suggest doing all processing in the Excel workbook instead of trying
to control Excel via the command line.

To open an Excel workbook, you can just enter the full path/filename for the
file into your batch file.

In the Workbook_Open event subroutine for your workbook, you can call a
subroutine to do what you need to do. At the end of the subroutine, do
this:

ThisWorkbook.Save
Application.Quit

In order for this to work unattended, you'll either have to:

1) set your macro security to low (not recommended)

or

2) sign the workbook with selfcert.exe (available on the MS site somewhere)
so it will be trusted




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Creating a .bat file that opens, pauses & closes MS Excel

To launch Excel from a batch file "file path of Excel.exe" "file path of Excel file to run"

For example:
rem Launch Excel example..
"C:\Program Files\Microsoft Office\Office10\EXCEL.EXE C:\temp\Excel-file.xls"
rem All done.

Use Excel to update, Save and Close itself given the previously mentioned help (Private Sub Workbook_Open()...End Sub). There are no useful switches for you in
Excel in this instance :-(
For a "sleep" command I use SLEEP.EXE (in the DOS section): http://www.computerhope.com/dutil.htm

Toby Erkson
Oregon, USA

On Thu, 29 Apr 2004 15:11:28 -0700, "alexa" wrote:

I am a beginner programmer and have never created a .bat
file. Although I have "some" prior knowledge of VB.
I am in need of creating a bat file (or something
comparable) that I can put into Scheduler to run every
morning.

The idea is to open Excel (Excel is set up to open the
file automatically), pause for 30 seconds (an automatic
update happens during this time), save the file
(overwrite), and then close Excel.
I have not been successful finding switches for Excel
(start it, save and close). Any switches, examples or
ideas you can provide would be extremely helpful. Thanks,
Alexa


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Creating a .bat file that opens, pauses & closes MS Excel

Toby,

Thanks so much! Extremely helpful. After a lot of time searching, I
have also learned that there are no useful switches which is what
prompted me to get out here and ask for help. Thanks again. I'll let
you know if it works.

Best regards,
Alexa


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Creating a .bat file that opens, pauses & closes MS Excel


Thanks Gord! I think with all of your (Jake, you and Troy) help. I will
be able to get this done.

Best regards,
Alexa



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a .bat file that opens, pauses & closes MS Excel


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81
------------------------------------------------------------------------
tristanm81's Profile: http://www.excelforum.com/member.php...o&userid=22702
View this thread: http://www.excelforum.com/showthread...hreadid=214801

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Creating a .bat file that opens, pauses & closes MS Excel

Just put the following in your batch file, including the quotes:

"c:\documentpath\filename"

where 'documentpath' is the file's path and 'filename' is, well, you get the
idea.
Windows knows to open ".xls" files in Excel.

In the workbook, insert your code module/sub/whatever, then insert a call to
the macro in the Workbook_Open() Event (in the PersonalWorkbook module)

-EW


"tristanm81" wrote:


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81
------------------------------------------------------------------------
tristanm81's Profile: http://www.excelforum.com/member.php...o&userid=22702
View this thread: http://www.excelforum.com/showthread...hreadid=214801




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Creating a .bat file that opens, pauses & closes MS Excel

How about a .vbs file?

Save this text file as somename.VBS

Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = true
xlapp.workbooks.add
xlapp.workbooks.open "c:\yourpathto\yourfile.xls"
xlapp.run "yourfile.xls!macronamehere"





Change the path and filename to what you need.

When you double click on this .vbs file, excel will start, the file will open
and your macro will execute.



tristanm81 wrote:

I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM

--
tristanm81
------------------------------------------------------------------------
tristanm81's Profile: http://www.excelforum.com/member.php...o&userid=22702
View this thread: http://www.excelforum.com/showthread...hreadid=214801


--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.programming
Noe Noe is offline
external usenet poster
 
Posts: 20
Default Creating a .bat file that opens, pauses & closes MS Excel

How about use of the "startup" options?
But I can not get this to work... It works in WORD. Any .bat file gurus out
there?

call "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" /mMYMACRO
MYFILE.xls


"Eric White" wrote:

Just put the following in your batch file, including the quotes:

"c:\documentpath\filename"

where 'documentpath' is the file's path and 'filename' is, well, you get the
idea.
Windows knows to open ".xls" files in Excel.

In the workbook, insert your code module/sub/whatever, then insert a call to
the macro in the Workbook_Open() Event (in the PersonalWorkbook module)

-EW


"tristanm81" wrote:


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81
------------------------------------------------------------------------
tristanm81's Profile: http://www.excelforum.com/member.php...o&userid=22702
View this thread: http://www.excelforum.com/showthread...hreadid=214801


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Creating a .bat file that opens, pauses & closes MS Excel

Here is a sample VBS script. Save it in a standard text file with a .VBS
extension.

This example:

a.. creates an Excel object,
b.. opens a workbook,
c.. sets a value,
d.. runs a VBA routine,
e.. then tidies 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

--
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy
-

"Noe" wrote in message
...
How about use of the "startup" options?
But I can not get this to work... It works in WORD. Any .bat file gurus

out
there?

call "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" /mMYMACRO
MYFILE.xls


"Eric White" wrote:

Just put the following in your batch file, including the quotes:

"c:\documentpath\filename"

where 'documentpath' is the file's path and 'filename' is, well, you get

the
idea.
Windows knows to open ".xls" files in Excel.

In the workbook, insert your code module/sub/whatever, then insert a

call to
the macro in the Workbook_Open() Event (in the PersonalWorkbook module)

-EW


"tristanm81" wrote:


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81


------------------------------------------------------------------------
tristanm81's Profile:

http://www.excelforum.com/member.php...o&userid=22702
View this thread:

http://www.excelforum.com/showthread...hreadid=214801




  #14   Report Post  
Posted to microsoft.public.excel.programming
Noe Noe is offline
external usenet poster
 
Posts: 20
Default Creating a .bat file that opens, pauses & closes MS Excel

Here is what I created:

Set xlObj = CreateObject("Excel.application")
xlObj.Workbooks.Open "MYWORKBOOK.xls"
xlObj.Run "PERSONAL.XLS!MYMACRO"
xlObj.ActiveWorkbook.Saved = True
xlObj.ActiveWindow.Close
xlObj.Quit

But it did not "take/work"...I did not see EXCEL open/run...

I realy like the batfile approach, because I can check Retrun Codes...

"Andy Wiggins" wrote:

Here is a sample VBS script. Save it in a standard text file with a .VBS
extension.

This example:

a.. creates an Excel object,
b.. opens a workbook,
c.. sets a value,
d.. runs a VBA routine,
e.. then tidies 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

--
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy
-

"Noe" wrote in message
...
How about use of the "startup" options?
But I can not get this to work... It works in WORD. Any .bat file gurus

out
there?

call "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" /mMYMACRO
MYFILE.xls


"Eric White" wrote:

Just put the following in your batch file, including the quotes:

"c:\documentpath\filename"

where 'documentpath' is the file's path and 'filename' is, well, you get

the
idea.
Windows knows to open ".xls" files in Excel.

In the workbook, insert your code module/sub/whatever, then insert a

call to
the macro in the Workbook_Open() Event (in the PersonalWorkbook module)

-EW


"tristanm81" wrote:


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81

------------------------------------------------------------------------
tristanm81's Profile:

http://www.excelforum.com/member.php...o&userid=22702
View this thread:

http://www.excelforum.com/showthread...hreadid=214801





  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Creating a .bat file that opens, pauses & closes MS Excel

To run the VBS you must have Windows Scripting Host (WSH) installed.

see: MSDN Online: Windows Scripting

http://msdn.microsoft.com/library/de...scriptinga.asp



--
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy
-

"Noe" wrote in message
...
Here is what I created:

Set xlObj = CreateObject("Excel.application")
xlObj.Workbooks.Open "MYWORKBOOK.xls"
xlObj.Run "PERSONAL.XLS!MYMACRO"
xlObj.ActiveWorkbook.Saved = True
xlObj.ActiveWindow.Close
xlObj.Quit

But it did not "take/work"...I did not see EXCEL open/run...

I realy like the batfile approach, because I can check Retrun Codes...

"Andy Wiggins" wrote:

Here is a sample VBS script. Save it in a standard text file with a .VBS
extension.

This example:

a.. creates an Excel object,
b.. opens a workbook,
c.. sets a value,
d.. runs a VBA routine,
e.. then tidies 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

--
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy
-

"Noe" wrote in message
...
How about use of the "startup" options?
But I can not get this to work... It works in WORD. Any .bat file

gurus
out
there?

call "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" /mMYMACRO
MYFILE.xls


"Eric White" wrote:

Just put the following in your batch file, including the quotes:

"c:\documentpath\filename"

where 'documentpath' is the file's path and 'filename' is, well, you

get
the
idea.
Windows knows to open ".xls" files in Excel.

In the workbook, insert your code module/sub/whatever, then insert a

call to
the macro in the Workbook_Open() Event (in the PersonalWorkbook

module)

-EW


"tristanm81" wrote:


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and

then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81


------------------------------------------------------------------------
tristanm81's Profile:

http://www.excelforum.com/member.php...o&userid=22702
View this thread:

http://www.excelforum.com/showthread...hreadid=214801









  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Creating a .bat file that opens, pauses & closes MS Excel

You can make it visible by adding this line.
xlobj.visible = true

But you'll have to load your personal.xls workbook in the script.

Here's a thread with a few options:

http://groups.google.co.uk/group/mic...4b901d22c9b77d

or

http://snipurl.com/h4zw





Noe wrote:

Here is what I created:

Set xlObj = CreateObject("Excel.application")
xlObj.Workbooks.Open "MYWORKBOOK.xls"
xlObj.Run "PERSONAL.XLS!MYMACRO"
xlObj.ActiveWorkbook.Saved = True
xlObj.ActiveWindow.Close
xlObj.Quit

But it did not "take/work"...I did not see EXCEL open/run...

I realy like the batfile approach, because I can check Retrun Codes...

"Andy Wiggins" wrote:

Here is a sample VBS script. Save it in a standard text file with a .VBS
extension.

This example:

a.. creates an Excel object,
b.. opens a workbook,
c.. sets a value,
d.. runs a VBA routine,
e.. then tidies 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

--
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy
-

"Noe" wrote in message
...
How about use of the "startup" options?
But I can not get this to work... It works in WORD. Any .bat file gurus

out
there?

call "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" /mMYMACRO
MYFILE.xls


"Eric White" wrote:

Just put the following in your batch file, including the quotes:

"c:\documentpath\filename"

where 'documentpath' is the file's path and 'filename' is, well, you get

the
idea.
Windows knows to open ".xls" files in Excel.

In the workbook, insert your code module/sub/whatever, then insert a

call to
the macro in the Workbook_Open() Event (in the PersonalWorkbook module)

-EW


"tristanm81" wrote:


I know absolutely nothing about writing batch files...

Is it possible to write a simple one that opens a workbook, and then
runs a specific macro ? If so , what would it look like?

thanks,

TNM


--
tristanm81

------------------------------------------------------------------------
tristanm81's Profile:

http://www.excelforum.com/member.php...o&userid=22702
View this thread:

http://www.excelforum.com/showthread...hreadid=214801






--

Dave Peterson
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
Hyperlink to pdf opens and closes Barbara Excel Discussion (Misc queries) 2 September 18th 12 09:07 PM
excel Visual basic opens then closes for users steve Excel Discussion (Misc queries) 0 March 3rd 10 05:15 PM
Excel file opens and opens and opens Wanna Learn Excel Discussion (Misc queries) 1 June 9th 09 11:03 PM
Excel 2003 File Closes In 2000 [email protected] Links and Linking in Excel 0 March 5th 05 05:20 PM
programmatically close help file before Excel closes? RB Smissaert Excel Programming 2 July 21st 03 11:49 AM


All times are GMT +1. The time now is 08:06 PM.

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"