Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Unexplained read-only from a batch file

Hi folks. I have a custom toolbar button in Word that uses the VBA's
Shell command to run a batch file:

Shell "C:\GX\OpenLog15.bat"

where the batch file reads:

@echo off
EXCEL.EXE C:\GX\Log15.xls
exit

It works fine, UNLESS Excel is already open with no sheet active AND the
last-opened Excel file is the one shown. In that case it displays the
File-In-Use dialog. Stranger still, if I dismiss that dialog by hitting
Cancel, the file comes up normally (not read-only).

Am I going about this wrong? Running XL 2003, WinXP.

Thanks for any clues.



Mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Unexplained read-only from a batch file

I think I'd drop the .bat file and use something like:

Option Explicit
Sub testme()

Dim XLApp As Object
Dim xlWkbk As Object
Dim wkbkName As String
Dim XLWasRunning As Boolean
Dim testStr As String
Dim iCtr As Long

wkbkName = "C:\GX\Log15.xls"

testStr = ""
on Error Resume Next
testStr = Dir(wkbkName)
On Error GoTo 0
If testStr = "" Then
MsgBox wkbkName & " wasn't found!"
Exit Sub
End If

XLWasRunning = True
On Error Resume Next
Set XLApp = GetObject(, "Excel.Application")
If Err.Number < 0 Then
Set XLApp = CreateObject("Excel.Application")
XLWasRunning = False
End If

XLApp.Visible = True 'at least for testing!

Set XLWkbk = XLApp.workbooks.Open(FileName:=wkbkName)

'do some stuff
'and close and save???
XLWkbk.Close savechanges:=True

If XLWasRunning Then
'leave it running
Else
XLApp.Quit
End If

Set XLWkbk = Nothing
Set XLApp = Nothing

End Sub

Mark Tangard wrote:

Hi folks. I have a custom toolbar button in Word that uses the VBA's
Shell command to run a batch file:

Shell "C:\GX\OpenLog15.bat"

where the batch file reads:

@echo off
EXCEL.EXE C:\GX\Log15.xls
exit

It works fine, UNLESS Excel is already open with no sheet active AND the
last-opened Excel file is the one shown. In that case it displays the
File-In-Use dialog. Stranger still, if I dismiss that dialog by hitting
Cancel, the file comes up normally (not read-only).

Am I going about this wrong? Running XL 2003, WinXP.

Thanks for any clues.

Mark


--

Dave Peterson
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
batch process to covert file to excel file [email protected] Excel Programming 4 February 22nd 08 10:09 PM
Unexplained File sinze Increase Cheryl M Excel Discussion (Misc queries) 1 June 25th 07 03:40 PM
Would Like to Automate Batch File Creation and Text FIle Import socrtwo Excel Discussion (Misc queries) 2 August 18th 06 03:54 PM
File sizes unexplained bloating Steve J Excel Discussion (Misc queries) 2 January 31st 05 10:29 AM
Create a batch file from a number of Excel File Vinay[_2_] Excel Programming 0 September 8th 04 01:11 AM


All times are GMT +1. The time now is 12:00 PM.

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"