Question : Defining a SourceWorkbook dynamically

How do I modify the code below so that instead of defining the source workbook absolutely, it defines the source workbook as the one whose full path and name are in cell AB1?

Thanks!
John
Code Snippet:
1:
2:
3:
Dim SourceWorkbook As Workbook
   Dim Area As Range
   Set SourceWorkbook = Workbooks("ETD_2009-10-31_Restructure.xls")

Answer : Defining a SourceWorkbook dynamically

Hello John,

This tests to see if the file is open, and if not, it opens the file:

    Dim SourceWorkbook As Workbook
    Dim Area As Range
    Dim SourceWbPath As String
    Dim SourceWbName As String

    SourceWbPath = ThisWorkbook.Worksheets("some sheet").[ab1]
    SourceWbName = Mid(SourceWbPath, InStrRev(SourceWbPath, "\") + 1)

    On Error Resume Next
    Set SourceWorkbook = Workbooks(SourceWbName)
    If Err <> 0 Then
        Err.Clear
        Set SourceWorkbook = Workbooks.Open(SourceWbPath)
    End If
    On Error GoTo 0


Regards,

Patrick
Random Solutions  
 
programming4us programming4us