ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is there a way to test first if MySampleAll.xls is already open (https://www.excelbanter.com/excel-programming/340446-there-way-test-first-if-mysampleall-xls-already-open.html)

CRayF

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€¦


Bob Phillips[_6_]

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.




CRayF

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.





Bob Phillips[_6_]

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.







CRayF

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.









All times are GMT +1. The time now is 10:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com