Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Is there a way to test first if MySampleAll.xls is already open

I have created file called StartExcelApp.vbs
That is coded:

Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = true
xlapp.workbooks.open "MySampleAll.xls"
xlapp.ActiveWorkbook.RunAutoMacros 1

Is there a way to test first if MySampleAll.xls is already open so that I am
not starting a second copy. When the MySampleAll.xls is opened it runs an
auto macro that updates some data and then immediately €śsaves€ť the workbook.
The macro errors because the second iteration is now set to read only? I only
want 1 copy open so if this VBS is runs when MySampleAll.xls is already open,
I want it to end without opening it€¦

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is there a way to test first if MySampleAll.xls is already open

On Error Resume Next
Set XLWkb = Workbooks("MySample.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("MySample.xls")
End If

--
HTH

Bob Phillips

"CRayF" wrote in message
...
I have created file called StartExcelApp.vbs
That is coded:

Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = true
xlapp.workbooks.open "MySampleAll.xls"
xlapp.ActiveWorkbook.RunAutoMacros 1

Is there a way to test first if MySampleAll.xls is already open so that I

am
not starting a second copy. When the MySampleAll.xls is opened it runs an
auto macro that updates some data and then immediately "saves" the

workbook.
The macro errors because the second iteration is now set to read only? I

only
want 1 copy open so if this VBS is runs when MySampleAll.xls is already

open,
I want it to end without opening it.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Is there a way to test first if MySampleAll.xls is already ope

Error Line 9 Object Required...
I tried changing line 9 from
If XLWkb Is Nothing Then
To
If XLWkb = "" Then
And that runs with no error, but allows multi copies of the XLS to run...
My ultimate goal would be to just go to the already opened one but I'd
settle to just abort the script.

-------------
Dim XLApp
Dim XLWkb
On Error Resume Next
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = true

Set XLWkb = Workbooks("RaceBetting.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("RaceBetting.xls")
XLApp.ActiveWorkbook.RunAutoMacros 1
End If
-----------------------

"Bob Phillips" wrote:

On Error Resume Next
Set XLWkb = Workbooks("MySample.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("MySample.xls")
End If

--
HTH

Bob Phillips

"CRayF" wrote in message
...
I have created file called StartExcelApp.vbs
That is coded:

Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = true
xlapp.workbooks.open "MySampleAll.xls"
xlapp.ActiveWorkbook.RunAutoMacros 1

Is there a way to test first if MySampleAll.xls is already open so that I

am
not starting a second copy. When the MySampleAll.xls is opened it runs an
auto macro that updates some data and then immediately "saves" the

workbook.
The macro errors because the second iteration is now set to read only? I

only
want 1 copy open so if this VBS is runs when MySampleAll.xls is already

open,
I want it to end without opening it.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is there a way to test first if MySampleAll.xls is already ope

Sorry, you need to declare your variable types

Dim XLApp As Application
Dim XLWkb As Workbook
On Error Resume Next
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = True

Set XLWkb = XLApp.Workbooks("RaceBetting.xls")
On Error GoTo 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("RaceBetting.xls")
XLApp.ActiveWorkbook.RunAutoMacros 1
End If


--
HTH

Bob Phillips

"CRayF" wrote in message
...
Error Line 9 Object Required...
I tried changing line 9 from
If XLWkb Is Nothing Then
To
If XLWkb = "" Then
And that runs with no error, but allows multi copies of the XLS to run...
My ultimate goal would be to just go to the already opened one but I'd
settle to just abort the script.

-------------
Dim XLApp
Dim XLWkb
On Error Resume Next
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = true

Set XLWkb = Workbooks("RaceBetting.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("RaceBetting.xls")
XLApp.ActiveWorkbook.RunAutoMacros 1
End If
-----------------------

"Bob Phillips" wrote:

On Error Resume Next
Set XLWkb = Workbooks("MySample.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("MySample.xls")
End If

--
HTH

Bob Phillips

"CRayF" wrote in message
...
I have created file called StartExcelApp.vbs
That is coded:

Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = true
xlapp.workbooks.open "MySampleAll.xls"
xlapp.ActiveWorkbook.RunAutoMacros 1

Is there a way to test first if MySampleAll.xls is already open so

that I
am
not starting a second copy. When the MySampleAll.xls is opened it runs

an
auto macro that updates some data and then immediately "saves" the

workbook.
The macro errors because the second iteration is now set to read only?

I
only
want 1 copy open so if this VBS is runs when MySampleAll.xls is

already
open,
I want it to end without opening it.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Is there a way to test first if MySampleAll.xls is already ope

That received a Error Line 1 Char 11

Adding your lines:
Dim XLApp As Application
Dim XLWkb As Workbook
errors off with "Error Line 1 Char 11".
Before, it had these coded instead and runs with no error, but starts a
second copy instead of terminating the script.

Dim XLApp
Dim XLWkb
-------------------------------
Dim XLApp As Application
Dim XLWkb As Workbook

On Error Resume Next
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = True

Set XLWkb = XLApp.Workbooks("RaceBetting.xls")
On Error GoTo 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("RaceBetting.xls")
XLApp.ActiveWorkbook.RunAutoMacros 1
End If
---------------------------

any clues?

"Bob Phillips" wrote:

Sorry, you need to declare your variable types

Dim XLApp As Application
Dim XLWkb As Workbook
On Error Resume Next
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = True

Set XLWkb = XLApp.Workbooks("RaceBetting.xls")
On Error GoTo 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("RaceBetting.xls")
XLApp.ActiveWorkbook.RunAutoMacros 1
End If


--
HTH

Bob Phillips

"CRayF" wrote in message
...
Error Line 9 Object Required...
I tried changing line 9 from
If XLWkb Is Nothing Then
To
If XLWkb = "" Then
And that runs with no error, but allows multi copies of the XLS to run...
My ultimate goal would be to just go to the already opened one but I'd
settle to just abort the script.

-------------
Dim XLApp
Dim XLWkb
On Error Resume Next
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = true

Set XLWkb = Workbooks("RaceBetting.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("RaceBetting.xls")
XLApp.ActiveWorkbook.RunAutoMacros 1
End If
-----------------------

"Bob Phillips" wrote:

On Error Resume Next
Set XLWkb = Workbooks("MySample.xls")
On Error Goto 0
If XLWkb Is Nothing Then
Set XLWkb = XLApp.Workbooks.Open("MySample.xls")
End If

--
HTH

Bob Phillips

"CRayF" wrote in message
...
I have created file called StartExcelApp.vbs
That is coded:

Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = true
xlapp.workbooks.open "MySampleAll.xls"
xlapp.ActiveWorkbook.RunAutoMacros 1

Is there a way to test first if MySampleAll.xls is already open so

that I
am
not starting a second copy. When the MySampleAll.xls is opened it runs

an
auto macro that updates some data and then immediately "saves" the
workbook.
The macro errors because the second iteration is now set to read only?

I
only
want 1 copy open so if this VBS is runs when MySampleAll.xls is

already
open,
I want it to end without opening it.







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
Excel already open test Nigel Excel Programming 4 May 7th 05 07:00 AM
Test if spreadsheet id open in IE Jan Kronsell[_4_] Excel Programming 6 April 11th 05 09:53 PM
Test to see if a workbook is open Alex St-Pierre Excel Programming 3 February 17th 05 05:40 PM
Test for Open File Aaron Excel Programming 6 January 6th 05 12:37 PM
Test that a workbook is open Gef[_2_] Excel Programming 2 April 6th 04 11:17 AM


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