Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default execl to check if another excel file is open...

I need my one excel workbook to check if another one is open before it
copies across to it and if it is open to exit the copy sub and display
please try again later....can any help?



TIA


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default execl to check if another excel file is open...

This code should be close...

Dim wbk As Workbook

On Error Resume Next
Set wbk = Workbooks("MyBook.xls")
On Error GoTo 0

If wbk Is Nothing Then MsgBox "Can't find it"

HTH

"ohboy!" wrote:

I need my one excel workbook to check if another one is open before it
copies across to it and if it is open to exit the copy sub and display
please try again later....can any help?



TIA



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default execl to check if another excel file is open...


"Jim Thomlinson" wrote in message
...
This code should be close...

Dim wbk As Workbook

On Error Resume Next
Set wbk = Workbooks("MyBook.xls")
On Error GoTo 0

If wbk Is Nothing Then MsgBox "Can't find it"

HTH

"ohboy!" wrote:

I need my one excel workbook to check if another one is open before it
copies across to it and if it is open to exit the copy sub and display
please try again later....can any help?



TIA


Hi there - thanks for tip - did the following in the end:

Option Explicit
Option Compare Text

Function IsWbOpen(wbName As String) As Boolean
Dim i As Long
For i = Workbooks.Count To 1 Step -1
If Workbooks(i).Name = wbName Then Exit For
Next
If i < 0 Then IsWbOpen = True

End Function


Sub openquery()

If MsgBox("This facility is only for transfering information into " _
+ "the Central Register repository database. " _
+ "Are you sure you want to continue?", vbQuestion + vbYesNo) = vbNo
Then
Exit Sub
End If

Dim wb As Workbook, strName As String, strPath As String
strName = "Book3.xls"
strPath = "C:\

If IsWbOpen("Book3.xls") Then
MsgBox "The Repository is being used try again in a moment."
Exit Sub
Else: Worksheets("Register").Select
ActiveSheet.Unprotect
Dim bk1 As Workbook
Dim bk2 As Workbook
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim idx As Long
Set bk1 = ActiveWorkbook
Set bk2 = Workbooks.Open("C:\Book3.xls")
Set sh1 = bk1.Worksheets("Register")

On Error Resume Next
Set sh2 = bk2.Worksheets("WPP")
On Error GoTo 0
If Not sh2 Is Nothing Then
idx = sh2.Index
Application.DisplayAlerts = False
sh2.Delete
Application.DisplayAlerts = True
If idx 1 Then
sh1.Copy after:=bk2.Sheets(idx - 1)
Else
sh1.Copy befo=bk2.Sheets(2)
End If
Else
sh1.Copy after:=bk2.Worksheets(bk2.Worksheets.Count)
End If
ActiveSheet.Name = "WPP"
ActiveWorkbook.Save
ActiveWorkbook.Close

End If


End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default execl to check if another excel file is open...

Hi Jim,
If the file is open in another instance,your code won't work.
Can you tell me how to deal with it?
Thanks
Yong

"Jim Thomlinson" wrote:

This code should be close...

Dim wbk As Workbook

On Error Resume Next
Set wbk = Workbooks("MyBook.xls")
On Error GoTo 0

If wbk Is Nothing Then MsgBox "Can't find it"

HTH

"ohboy!" wrote:

I need my one excel workbook to check if another one is open before it
copies across to it and if it is open to exit the copy sub and display
please try again later....can any help?



TIA



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default execl to check if another excel file is open...


Have a look here for this ..........

http://www.xcelfiles.com/IsFileOpen.html


--
Ivan F Moala


------------------------------------------------------------------------
Ivan F Moala's Profile: http://www.excelforum.com/member.php...fo&userid=1954
View this thread: http://www.excelforum.com/showthread...hreadid=370728

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
How to check for Open File! Ayo Excel Discussion (Misc queries) 2 August 11th 08 06:55 PM
Cant open Execl file-Not a valid win32 Application Albert Excel Discussion (Misc queries) 0 August 10th 08 08:34 AM
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
How to check Excel file already Open Rudy S Excel Programming 2 January 25th 05 02:00 PM
check if a file exists / is open Mark Kubicki Excel Programming 1 December 4th 03 05:56 PM


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