Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Error Handle: File is already open.

I have the following script for adding a workbook. What error handling can I
add so that it tells the user the file name they try to create already exists
and is open. Then exits the program. I would liek to use a more specific
method than "On error goto ErrHandle"

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fName = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fName < False
If UCase(Right(fName, 4)) < ".XLS" Then fName = fName + "xls"

ReportBook.SaveAs Filename:=fName

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Error Handle: File is already open.

You could do something like this...

Dim ReportBook As Workbook
Dim ReportPage As Worksheet
Dim fname As String

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fname = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fname < "False" 'note False is a string
If UCase(Right(fname, 4)) < ".XLS" Then fname = fname + "xls"

If Len(Dir(fname)) 0 Then
MsgBox fname & " already exists. File Not Saved"
Else
ReportBook.SaveAs Filename:=fname
End If
--
HTH...

Jim Thomlinson


"J@Y" wrote:

I have the following script for adding a workbook. What error handling can I
add so that it tells the user the file name they try to create already exists
and is open. Then exits the program. I would liek to use a more specific
method than "On error goto ErrHandle"

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fName = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fName < False
If UCase(Right(fName, 4)) < ".XLS" Then fName = fName + "xls"

ReportBook.SaveAs Filename:=fName

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Error Handle: File is already open.

Sorry. I did not read your question correctly. You wanted to know if the file
was open. Give this a look see...

Dim ReportBook As Workbook
Dim ReportPage As Worksheet
Dim fname As String
Dim wbk As Workbook

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fname = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fname < "False"
If UCase(Right(fname, 4)) < ".XLS" Then fname = fname + "xls"

If Len(Dir(fname)) 0 Then
MsgBox fname & " already exists."
On Error Resume Next
Set wbk = Workbooks(Dir(fname))
On Error GoTo 0
If wbk Is Nothing Then
MsgBox fname & " is not open. File saved."
ReportBook.SaveAs Filename:=fname
Else
MsgBox fname & " is open. File Not Saved."
End If
Else
ReportBook.SaveAs Filename:=fname
End If
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

You could do something like this...

Dim ReportBook As Workbook
Dim ReportPage As Worksheet
Dim fname As String

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fname = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fname < "False" 'note False is a string
If UCase(Right(fname, 4)) < ".XLS" Then fname = fname + "xls"

If Len(Dir(fname)) 0 Then
MsgBox fname & " already exists. File Not Saved"
Else
ReportBook.SaveAs Filename:=fname
End If
--
HTH...

Jim Thomlinson


"J@Y" wrote:

I have the following script for adding a workbook. What error handling can I
add so that it tells the user the file name they try to create already exists
and is open. Then exits the program. I would liek to use a more specific
method than "On error goto ErrHandle"

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fName = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fName < False
If UCase(Right(fName, 4)) < ".XLS" Then fName = fName + "xls"

ReportBook.SaveAs Filename:=fName

  #4   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Error Handle: File is already open.

Thanks, I found a way to use err number

"Jim Thomlinson" wrote:

Sorry. I did not read your question correctly. You wanted to know if the file
was open. Give this a look see...

Dim ReportBook As Workbook
Dim ReportPage As Worksheet
Dim fname As String
Dim wbk As Workbook

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fname = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fname < "False"
If UCase(Right(fname, 4)) < ".XLS" Then fname = fname + "xls"

If Len(Dir(fname)) 0 Then
MsgBox fname & " already exists."
On Error Resume Next
Set wbk = Workbooks(Dir(fname))
On Error GoTo 0
If wbk Is Nothing Then
MsgBox fname & " is not open. File saved."
ReportBook.SaveAs Filename:=fname
Else
MsgBox fname & " is open. File Not Saved."
End If
Else
ReportBook.SaveAs Filename:=fname
End If
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

You could do something like this...

Dim ReportBook As Workbook
Dim ReportPage As Worksheet
Dim fname As String

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fname = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fname < "False" 'note False is a string
If UCase(Right(fname, 4)) < ".XLS" Then fname = fname + "xls"

If Len(Dir(fname)) 0 Then
MsgBox fname & " already exists. File Not Saved"
Else
ReportBook.SaveAs Filename:=fname
End If
--
HTH...

Jim Thomlinson


"J@Y" wrote:

I have the following script for adding a workbook. What error handling can I
add so that it tells the user the file name they try to create already exists
and is open. Then exits the program. I would liek to use a more specific
method than "On error goto ErrHandle"

Set ReportBook = Workbooks.Add()
Set ReportPage = Worksheets.Add
ReportPage.Name = "Report"


Do
fName = Application.GetSaveAsFilename(Title:="Specify Report Name")
Loop Until fName < False
If UCase(Right(fName, 4)) < ".XLS" Then fName = fName + "xls"

ReportBook.SaveAs Filename:=fName

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
Open Excel file get error with file names that have spaces in the Kozmo Setting up and Configuration of Excel 6 October 29th 08 02:51 AM
EXCEL:Can't open any file without error saying it's ALREADY open??? Crackles McFarly Excel Worksheet Functions 1 November 1st 07 02:22 AM
How to handle error 8007000e Memory Error L. A. M. Excel Programming 6 June 28th 05 04:05 AM
Handle password for open workbook? Marc[_20_] Excel Programming 1 March 17th 05 06:30 PM
open file file then error message Piroon Saetang Excel Discussion (Misc queries) 1 February 4th 05 12:05 AM


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