Open a workbook using a stored name

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

I have several workbooks (call them WB1 and WB2) that moves data to a central
workbook (call it WBMain and its name never changes). Once WB1 or WB2 has
passed their data it leaves WBMain activated. At the time WBMain was
activated the name and path for WB1 or WB2 was stored on WBMain in named
cells (WBName & WBPath). My problem, although it should not happen, if the
user closes WB1 or WB2 while in WBMain then when required to go back to WB1
or WB2 it must do so using the name and path stored on WBMain. I can't seem
to get it done.
 
Refer the workbooks as an object...

Dim wbBook As Workbook
'To reference a open workbook (already saved)
Set wbMain = Workbooks("WBMain.xls")

'Now where ever you are you can reference the range as
Msgbox wbMain.Sheets("Sheet1").Range("A1")

If this post helps click Yes
 
Not exactly what I am looking for. I want to activate WB1 or WB2 if it is
still open or re-open WB1 or WB2 if closed. I have tried this

Dim WBName as Workbook
WBName = Range(“WBNameâ€)
WBName.Activate

Just to use the workbooks saved name but I get an error message.
 
Well, use a function as below which returns a boolean

Sub Macro1()
If IsBookOpen("filename.xls") Then
'Workbook open refer the same object
Else
'Open the workbook and refer
End If
End Sub

Function IsBookOpen(strWBName As String) As Boolean
On Error Resume Next
IsBookOpen = Not (Application.Workbooks(strWBName) Is Nothing)
End Function



If this post helps click Yes
 
Back
Top