LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Opening Excel Workbook More Than Once

I have the following Macro that works, but I am trying to make it check to
see if the workbook is already open . . . and if it is open, to give the
message and not open the file again.

Can someone give me a hand please.

Matt@Launchnet



Sub NewExcelWithWorkbookSpecialOne()
Dim oXL As Object 'This is needed to open a new instance of Excel.
'Without it, the file is only opened as a new Window

Dim testFileFind
Dim oWB As Object

'The following tests for the existance of the file



'THIS MAY BE PROBLEM AREA . . .ALSO SEE FURTHER DOWN THE CODE JUST AFTER
'THE 'FOLLOWING IF STATEMENT WHERE THE PROBLEM MIGHT ALSO BE.

'I MAY BE COMPLETELY OFF.

testFileFind = Dir("c:\extrafiles\special1.xls") 'TRIED THIS FOR DIRECT
OPENING
'END OF PROBLEM AREA



'If the file is not found there will be nothing
'in the variable and processing ends.

If Len(testFileFind) = 0 Then
MsgBox "You do not have this file in C:\extrafiles\"
'Invalid selection." & Chr(13) & _"Filename " & ActiveCell & " not found"
End
End If







'I THINK I NEED SOMETHING LIKE THIS HERE, BUT NONE OF MY IDEAS WORK.

'ADDED FOR TEST
'Check if the file is already open, do nothing if so
'If Not IsFileOpen(ActiveCell.Value) Then
'NEW TRY
'If Not IsFileOpen("c:\extrafiles\special1.xls") Then
'NEW TRY
'If Not IsFileOpen(testFileFind) Then
'NEW TRY
'If Not IsFileOpen("c:\extrafiles\special1.xls") Then
'END ADD

'???????????????????????????????????????







'THIS LINE OF CODE OPENS THE NEW INSTANCE OF EXCEL.
Set oXL = CreateObject("Excel.Application")

'THIS LINE OF CODE MAKES THE NEW INSTANCE OF EXCEL VISIBLE.
oXL.Visible = True

Set oWB = oXL.Workbooks.Open("c:\extrafiles\special1.xls")


'ADDED FOR TEST TO DISPLAY MESSAGE
Else

MsgBox "File " & ActiveCell.Value & " is already open"
End If
'END ADD



End Sub

--
Please take a look at www.openoursite.com Click on: "Keywords" and then
Click on "Matt's Story" and if you are a man, you should be very happy that
you read my story. God Bless for everyones help.

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1

 
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
when opening an Excel Workbook, another blank workbook also opens Gord Dibben Excel Discussion (Misc queries) 0 October 12th 07 09:49 PM
when opening an Excel Workbook, another blank workbook also opens spmu Excel Discussion (Misc queries) 0 October 12th 07 01:46 PM
excel VBA problem - setting workbook as variable & opening/re-opening safe Excel Programming 1 August 20th 04 12:22 AM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM
How to make opening of workbook conditional of opening of another workbook turk5555[_2_] Excel Programming 2 December 15th 03 11:07 PM


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