Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default VBA + VB Script fails to open the workbook.

Hi all,

I use the following VB Script to open an XLA and execute a macro.

Dim objxl, xlapath, macro

Set objxl = CreateObject("Excel.Application")
xlapath = "C:\myxla.xla"
macro="myxla.xla!macro1(""param1"",""param2"")"

With objxl
.Visible = True
.Workbooks.Open xlapath
.Workbooks("myxla.xla").RunAutoMacros 1 'xlAutoOpen
.Run macro
End With

Within the xla-macro, I try to open another workbook.

Public Sub macro1(param1 As String, param2 As String)
Dim wb As Workbook
Dim url As String

url = "http://localhost/test.csv"

Debug.Print "Attempting to open : " & url

Set wb = Workbooks.Open(Filename:=url, UpdateLinks:=False,
ReadOnly:=True, Editable:=False, AddToMru:=False, Format:=1)
If wb Is Nothing Then
Debug.Print "Could not open the page: " & url
else
Debug.Print "Successfully opened : " & url
End If
End Sub


This macro works if I invoke it from VBA. But doesnot work (the workbook is
never opened, and wb Is Nothing), if I invoke it using the VB Script.

Could someone please tell me what I am doing wrong ? Is there a better way
to do this ?



Thanks in advance.


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
Script fails in Excel was okay before. Jonah Excel Programming 14 March 5th 06 09:23 PM
Workbook fails to open - Excel 2003 nc Excel Discussion (Misc queries) 1 February 2nd 06 06:33 PM
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. san Excel Programming 1 January 3rd 06 03:22 AM
Excel fails to open workbook using Automation from VB 6 Lowell Excel Programming 0 September 8th 05 05:33 AM
Sheets select method fails when workbook is opened by another workbook Mike Excel Programming 2 June 8th 04 04:17 AM


All times are GMT +1. The time now is 04:57 AM.

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

About Us

"It's about Microsoft Excel"