Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel already open test | Excel Programming | |||
Test if spreadsheet id open in IE | Excel Programming | |||
Test to see if a workbook is open | Excel Programming | |||
Test for Open File | Excel Programming | |||
Test that a workbook is open | Excel Programming |