opening an excel file from another excel file

K

Keyur

hi

http://www.exceltip.com/st/ Determine_if_a_workbook_is_already_open_using_VBA_<br%20/>in_Microsoft_Excel/472.html

The function below can be used to determine if a workbook is open o
not:
Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Application.WorkBooks(WorkBookName).Name) > 0 Then
WorkbookOpen = True
Exit Function
End If
WorkBookNotOpen:
End Function

Example:
If Not WorkbookOpen("MyWorkbookName.xls") Then
Workbooks.Open "MyWorkbookName.xls"
End If



i am using the above function in an excel file to check if anothe
excel file is open. both the files are in the same folder. now i hav
to write the complete path since not in My Documents. can i set it u
so it will open the file from the same folder (as the file which ha
this function) without writing the complete path.

thanks
 
K

Keyur

hi

i figured it out i am defining a string path = activeworkbook.path
and then i am using

If Not WorkbookOpen("MyWorkbookName.xls") Then
Workbooks.Open path & "\MyWorkbookName.xls"
End If


thanks whoever read it and tried to help me
 
G

Guest

use the Dir method. Dir always returns the current directory path then just append the file name to the retuned value

----- Keyur > wrote: ----

h

http://www.exceltip.com/st/ Determine_if_a_workbook_is_already_open_using_VBA_<br%20/>in_Microsoft_Excel/472.htm

The function below can be used to determine if a workbook is open o
not:
Function WorkbookOpen(WorkBookName As String) As Boolea
' returns TRUE if the workbook is ope
WorkbookOpen = Fals
On Error GoTo WorkBookNotOpe
If Len(Application.WorkBooks(WorkBookName).Name) > 0 The
WorkbookOpen = Tru
Exit Functio
End I
WorkBookNotOpen
End Functio

Example:
If Not WorkbookOpen("MyWorkbookName.xls") Then
Workbooks.Open "MyWorkbookName.xls
End I



i am using the above function in an excel file to check if anothe
excel file is open. both the files are in the same folder. now i hav
to write the complete path since not in My Documents. can i set it u
so it will open the file from the same folder (as the file which ha
this function) without writing the complete path

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top