![]() |
Open a workbook using a stored name
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. |
Open a workbook using a stored name
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 --------------- Jacob Skaria "JB" wrote: 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. |
Open a workbook using a stored name
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. "Jacob Skaria" wrote: 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 --------------- Jacob Skaria "JB" wrote: 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. |
Open a workbook using a stored name
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 --------------- Jacob Skaria "JB" wrote: 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. "Jacob Skaria" wrote: 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 --------------- Jacob Skaria "JB" wrote: 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. |
All times are GMT +1. The time now is 01:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com