Hello and thank you for the speedy reply.
So with the above code do I can place that as a function then call in from another sub using
???
I tried this but it didn't seem to work. I'm not sure if I can include the Function as part of the Sub. I assume if this function runs before I switch worksheets it retains memory of the earlier active worksheet as I need to call the function while a different sheet is active.
My current coding set up is as follows:
Option Explicit
Option Compare Text
Function IsWbOpen(wbName As String) As Boolean
Dim i As Long
For i = Workbooks.Count To 1 Step -1
If Workbooks(i).Name = wbName Then Exit For
Next
If i <> 0 Then IsWbOpen = True
End Function
'\\ Example
Sub Pre_Subtract()
WorkbookName
Dim wb As Workbook, strName As String, strPath As String
strName = "My File name.xlsm"
strPath = "C:\excel\"
If IsWbOpen(strName) Then
Call Subtract
Else
Set wb = Workbooks.Open(strPath & strName)
Application.WindowState = xlMinimized
Call Subtract
End If
End Function
Workbooks(1).Activate '<<== This is where I would like to reference the workbook running the code
Various cell functions
Windows("PreKnowFileName.xlsm").Activate
Various cell functions
Application.WindowState = xlMinimized
Workbooks(1).Activate '<<== This is where I would like to reference the workbook running the code
Application.WindowState = xlMaximized
End Sub
I use 1 module to check if a certain workbook is open or not then call a macro to make some changes, then I need to return to the original worksheet which could have various names and as such I need to reference it in a cleaver fashion. My current index reference only works if I open the files in the right order.
Bookmarks