• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Open File

Dear all good morning

(Probably ther'es allready an answer for this question, but i could't find it)

So, i have a macro that runs another macros

Sub Report()

Call Macro 1
Call Macro 2
Etc...

End sub

But these macros need to have a specific file allready opened

So, i would need that this "Sub Report()" could do something like:

Sub Report ()

Dim Path as String
Path = Sheet ("File 1"). Range ("D4").Value

IF this Path is allready open, then Call those macros (Macro 1, Macro 2, Etc).
IF not open, than open this path and then Call the macros.


Many thanks

Regards
 
If Marc L doesn't satisfied you the loop it.

Code:
Option Explicit
Public Function Isopen(strWkbNm As String) As Boolean
    On Error Resume Next
    Dim wBook As Workbook
    Set wBook = Workbooks(strWkbNm)
    If wBook Is Nothing Then    'Not open
        Isopen = False
        Set wBook = Nothing
        On Error GoTo 0
    Else
        Isopen = True
        Set wBook = Nothing
        On Error GoTo 0
    End If
End Function

Sub Report()

Dim Path As String
Path = Sheet("File 1").Range("D4").Value

If Isopen(Path) = False Then Application.Workbooks.Open Path
Call ABC
Call XYZ
End Sub
 
Back
Top