0

I want to open a file by selecting it from a dialog box and set the workbook. Selecting the file and storing the file location in wbCombinedName works fine.

However, wbCombined is not always set properly. E.g. if I have the file open and save it, then run the marco it does not work. When I reopen the file it does work. When I check the variable wbCombined fullname I believe the name of the latest file opened is set.

Is there a way to adjust the below Set statement or should I include a check to see if the to be opened workbook is the already open workbook? Thanks

Set FileO = Application.FileDialog(msoFileDialogFilePicker)
With FileO
        .AllowMultiSelect = False
        If .Show <> -1 Then GoTo NextCode1
        wbCombinedName = .SelectedItems(1)
End With

Set wbCombined = Workbooks.Open(Filename:=wbCombinedName, UpdateLinks:=0)
Mr Watt
  • 65
  • 6

1 Answers1

1
Function WORKBOOK_OPEN(strWorkbookname As String, _
                        Optional strCheckPath As String = "") As Boolean

Dim w As Excel.Workbook

For Each w In Workbooks

    If w.Name = strWorkbookname Then

        WORKBOOK_OPEN = True

        If strCheckPath <> "" Then
            WORKBOOK_OPEN = w.Path = strCheckPath
        End If

    End If

Next w

End Function
Nathan_Sav
  • 8,466
  • 2
  • 13
  • 20