Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default macro will not run from vbscript. help please

I have a vbscript below that opens a file, runs a macro and saves the file.
Everything works fine except the macro part. I usualy get a message that
macro has not been found. However, the macro exists and runs just fine when I
go into excel and run it manualy. I have tried changing the path to the file
in XLSTART folder and it doesn't help. Also I have lowered security to low
but no difference there. Can anyone offer any suggestions please? Thanks.


Dim objExcel
Dim objWorkBook
Set objExcel = CreateObject("EXCEL.APPLICATION")
Set objWorkBook = objExcel.Workbooks.Open("File 1.xls")
objExcel.DisplayAlerts=False
objExcel.Run "PERSONAL.xls!FORMAT"
objWorkBook.SaveAs "file 2.xls",44
objExcel.DisplayAlerts=True
objWorkBook.Close True
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default macro will not run from vbscript. help please

When activated by OLE (CreateObject), Excel does not automatically open
PERSONAL.XLS.

Why do you create a new instance of Excel, since you already have one fully
operational.
You could simply use the instance your code is running in.

'----------------
Sub test()
Dim objWorkBook As Workbook
Set objWorkBook = Workbooks.Open("Ranking.xls")
DisplayAlerts = False
Run "PERSO.xls!FORMAT"
objWorkBook.SaveAs "file 2.xls", 44
DisplayAlerts = True
objWorkBook.Close True
End Sub
'-----------------
HTH
--
AP

"vedran" a écrit dans le message de news:
...
I have a vbscript below that opens a file, runs a macro and saves the file.
Everything works fine except the macro part. I usualy get a message that
macro has not been found. However, the macro exists and runs just fine
when I
go into excel and run it manualy. I have tried changing the path to the
file
in XLSTART folder and it doesn't help. Also I have lowered security to low
but no difference there. Can anyone offer any suggestions please? Thanks.


Dim objExcel
Dim objWorkBook
Set objExcel = CreateObject("EXCEL.APPLICATION")
Set objWorkBook = objExcel.Workbooks.Open("File 1.xls")
objExcel.DisplayAlerts=False
objExcel.Run "PERSONAL.xls!FORMAT"
objWorkBook.SaveAs "file 2.xls",44
objExcel.DisplayAlerts=True
objWorkBook.Close True
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default macro will not run from vbscript. help please

Thanks for the explanation! However, your script gives me 'Expected End of
statement' error on line 2.
I have tried adding Set objWorkBook =
objExcel.Workbooks.Open("Personal.xls") to my original script in addition to
opening file 1.xls and it worked. Would this be correct way to do it? Is
objWorkBook.Close True going to close both worksheets?

Thanks for your very fast response.



"Ardus Petus" wrote:

When activated by OLE (CreateObject), Excel does not automatically open
PERSONAL.XLS.

Why do you create a new instance of Excel, since you already have one fully
operational.
You could simply use the instance your code is running in.

'----------------
Sub test()
Dim objWorkBook As Workbook
Set objWorkBook = Workbooks.Open("Ranking.xls")
DisplayAlerts = False
Run "PERSO.xls!FORMAT"
objWorkBook.SaveAs "file 2.xls", 44
DisplayAlerts = True
objWorkBook.Close True
End Sub
'-----------------
HTH
--
AP

"vedran" a écrit dans le message de news:
...
I have a vbscript below that opens a file, runs a macro and saves the file.
Everything works fine except the macro part. I usualy get a message that
macro has not been found. However, the macro exists and runs just fine
when I
go into excel and run it manualy. I have tried changing the path to the
file
in XLSTART folder and it doesn't help. Also I have lowered security to low
but no difference there. Can anyone offer any suggestions please? Thanks.


Dim objExcel
Dim objWorkBook
Set objExcel = CreateObject("EXCEL.APPLICATION")
Set objWorkBook = objExcel.Workbooks.Open("File 1.xls")
objExcel.DisplayAlerts=False
objExcel.Run "PERSONAL.xls!FORMAT"
objWorkBook.SaveAs "file 2.xls",44
objExcel.DisplayAlerts=True
objWorkBook.Close True
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing




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
macro vbscript doesn't run !!! I am desperate! I need help ina Excel Programming 6 May 6th 06 10:43 PM
Please help with ADO and VBScript! jenhu[_2_] Excel Programming 1 March 23rd 06 05:06 PM
VBscript raji Excel Programming 0 September 22nd 04 08:03 PM
How to delete an Excel Macro from VBScript Ram[_3_] Excel Programming 1 September 3rd 03 11:18 PM
Calling xla argumented macro from VBScript Lieven Roelens Excel Programming 2 September 3rd 03 01:45 PM


All times are GMT +1. The time now is 11:20 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"