Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Opening a file from another file

I have a file File01.xls that has a macro that opens file File02.xls with :

Private Sub MacroOpenFile02()
Workbooks.Open Filename:= "C:\File02.xls", Password:="aoaoao"
Application.Run "'C:\File02.xls'!Auto_Open"
Windows("File01.xls").Close (0)
End Sub

If I already have the file open and accidentally click the macro to open it
again I will get a message that the file is already open, do I want to reopen
the file Yes, No. If I click Yes it opens File02.xls again and all is ok but
if I click No then I get an error. How do I handle this situation.

Thank you,

Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Opening a file from another file

Private Sub MacroOpenFile02()
dim Wkbk as workbook
dim myFileName as string
dim myPath as string

mypath = "C:\" '<- include that backslash!
myfilename = "file02.xls"

set wkbk = nothing
on error resume next
set wkbk = workbooks(myfileName)
on error goto 0

if wkbk is nothing then
'it's not open
set wkbk = workbooks.Open(Filename:=mypath & myfilename, _
Password:="aoaoao")
wkbk.runautomacros which:=xlAutoOpen
wkbk.close savechanges:=false
else
msgbox "The file is already open!"
end if
End Sub

The code only closed the file if it opened it.



Steven wrote:

I have a file File01.xls that has a macro that opens file File02.xls with :

Private Sub MacroOpenFile02()
Workbooks.Open Filename:= "C:\File02.xls", Password:="aoaoao"
Application.Run "'C:\File02.xls'!Auto_Open"
Windows("File01.xls").Close (0)
End Sub

If I already have the file open and accidentally click the macro to open it
again I will get a message that the file is already open, do I want to reopen
the file Yes, No. If I click Yes it opens File02.xls again and all is ok but
if I click No then I get an error. How do I handle this situation.

Thank you,

Steven


--

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
opening a file in Excel starts application but dose not open file Bob Shelton Excel Discussion (Misc queries) 1 July 2nd 08 07:51 PM
Opening file in Excel 2003 opens multipule instances of same file Ed_B Excel Discussion (Misc queries) 1 June 21st 07 07:10 PM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM


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