My code currently opens any workbook, document, video, etc. from 1 button. When it comes to opening a file that is already open, it gives the following message.
"This File Is Already Open"
I want to convert the code to activate (Display) the non-displayed workbook. In my sample code, I have 2 rows of rem'd X's to show where the problem is, I think.
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
Questionable Code
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
Sub NewExcelWithWorkbook()
Dim oXL As Object 'This is needed to open a new instance of Excel.
'Without it, the file is only opened as a new Window
Dim OpenFileName '<-this isn't used
Dim testFileFind As String
Dim oWB As Workbook
Dim Cl As Range
'This reads the cell 1 column to the Left so the path & file name can be read
Set Cl = ActiveCell.Offset(0, -1)
'The following tests for a blank cell and ends processing
'It is needed because dir() function will not work with a blank.
If Len(Trim(Cl)) = 0 Then
MsgBox "You have not entered a Path and File name."
End
End If
'The following tests for the existance of the file
testFileFind = Dir(Cl)
'If the file is not found there will be nothing in the variable and processing ends.
If Len(testFileFind) = 0 Then
MsgBox "Invalid selection." & Chr(13) & _
"Filename " & Cl.Value & " not found"
End
End If
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'THIS TESTS TO SEE IF THE DOCUMENT IS ALREADY OPEN AND IT WORKS
If FileAlreadyOpen(Cl.Value) = True Then
'THE FOLLOWING 2 LINES OF CODE ALSO WORK, GIVING THE MESSAGE BUT DOES NOT DISPLAY THE FILE
'ActivateWorkbook (FSS)
'MsgBox "File is already open"
'THE FOLLOWING LINE OF CODE IS WHAT I AM TRYING TO MAKE WORK. ActivateWorkbook does work.
ActivateWorkbook (testFileFind)
'(testFileFind) has the file name that I want displayed. Example: mytestfile.xls , BUT DOES NOT DISPLAY FILE
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
End
Else
End If
'THIS LINE OF CODE OPENS THE NEW INSTANCE OF EXCEL.
Set oXL = CreateObject("Excel.Application")
'THIS LINE OF CODE MAKES THE NEW INSTANCE OF EXCEL VISIBLE.
oXL.Visible = True
Set oWB = oXL.Workbooks.Open(Cl)
End Sub
Leith are you around?
Bookmarks