Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Workbook not Open Then Open It

How do check to see if a workbook's open, and if it's not already open
then open it?

I've looked in the forum, but nobody seems to be looking for the abov
condition.

I've got this already:

jbl = "Production Schedule 040512.xls"
checkForBook = CBool(Len(Workbooks(jbl).name))

If Not checkForBook Then

'What goes here?'

End I

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default If Workbook not Open Then Open It

Hi,

if checkForBook = false then workbooks.open jbl


-----Original Message-----
How do check to see if a workbook's open, and if it's

not already open,
then open it?

I've looked in the forum, but nobody seems to be looking

for the above
condition.

I've got this already:

jbl = "Production Schedule 040512.xls"
checkForBook = CBool(Len(Workbooks(jbl).name))

If Not checkForBook Then

'What goes here?'

End If


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default If Workbook not Open Then Open It

Umm...in addition to Wolf's suggestion, you also need an error trap.
Try something along the lines of

Sub testIt()
Dim JBL As String, JBLWB As Workbook
JBL = "Production Schedule 040512.xls"
On Error Resume Next
Set JBLWB = Workbooks(JBL)
On Error GoTo 0
If JBLWB Is Nothing Then
Set JBLWB = Workbooks.Open(JBL)
End If
End Sub

You still may have problems opening the workbook if the path is not
correct, but that is another story.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , scain2004
says...
How do check to see if a workbook's open, and if it's not already open,
then open it?

I've looked in the forum, but nobody seems to be looking for the above
condition.

I've got this already:

jbl = "Production Schedule 040512.xls"
checkForBook = CBool(Len(Workbooks(jbl).name))

If Not checkForBook Then

'What goes here?'

End If


---
Message posted from http://www.ExcelForum.com/


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Workbook not Open Then Open It

Ok, that worked, except I need the focus to remain on the callin
workbook. How should I do that?


Workbooks("Production Job List - 040516.xls").Activate

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default If Workbook not Open Then Open It

ThisWorkbook.Activate


"scain2004 " wrote in message
...
Ok, that worked, except I need the focus to remain on the calling
workbook. How should I do that?


Workbooks("Production Job List - 040516.xls").Activate ?


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Workbook not Open Then Open It

Ok, this is what I did and it works great:

cwb = "Workbook 1"
jbl = ThisWorkbook.Name

On Error Resume Next
Set wb = Workbooks(cwb)
On Error GoTo 0
If wb is Nothing Then
Set wb = Workbooks.Open(cwb)
End If

Application.Workbooks(jbl).Activate



Thanks!

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to: Open closed workbook/Search data tables/Return data to open workbook Hugh Adams Excel Discussion (Misc queries) 0 August 18th 10 02:04 PM
Opening Excel, Book1 opens, remains open with other workbook open DanieB Excel Discussion (Misc queries) 0 September 3rd 09 08:23 AM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
Search open sheets in workbook and insert into open sheet punx77 Excel Discussion (Misc queries) 0 March 6th 06 05:07 PM
Excel workbook does not open in open window on desktop DeanH Excel Discussion (Misc queries) 2 March 8th 05 09:51 AM


All times are GMT +1. The time now is 02:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"