Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How do I deal with several workbooks that are open in the ActiveWi

Can anyone help. The following code falls over if I have other excel files
open in the activewindow. I used to code quite regularly 18 months ago and I
seem to remember there was something to cater for this but I've forgotten
how. Can anyone remind me. Is it that I need to explicitly select my
workbook? See syntax below.
Thanks
Jacqui

Sub Qualifiers_Check()

Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")

With wks

Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))

Set myRng = myRng.Resize(myRng.Count - 1)

For Each myCell In myRng.Cells
If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 5)
If Application.CountA(myRngToCheck) < myRngToCheck.Cells.Count
Then
Beep

Msgbox "You have not supplied all the relevant information
for this Segment type in Row " _
& myCell.Row & " on the Coding Details Sheet -
PLEASE ENTER ALL DETAILS" _
, 48, "Change Request Form Error Checks"


myCell.Select


Exit For

End If
End If
Next myCell

End With



End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default How do I deal with several workbooks that are open in the ActiveWi

Jacqui:

You do need to explicitly set your workbook. For example:

Dim wkb As Workbook

Set wkb = Workbooks("TestTarget.xls")

Set wks = wkb.Worksheets("Part B - Coding Details")

or similarly:

Dim wkb As Workbook

Set wkb = Workbooks("TestTarget.xls")

wkb.Activate

Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


"Jacqui" wrote in message
...
Can anyone help. The following code falls over if I have other excel files
open in the activewindow. I used to code quite regularly 18 months ago and
I
seem to remember there was something to cater for this but I've forgotten
how. Can anyone remind me. Is it that I need to explicitly select my
workbook? See syntax below.
Thanks
Jacqui

Sub Qualifiers_Check()

Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")

With wks

Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))

Set myRng = myRng.Resize(myRng.Count - 1)

For Each myCell In myRng.Cells
If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 5)
If Application.CountA(myRngToCheck) < myRngToCheck.Cells.Count
Then
Beep

Msgbox "You have not supplied all the relevant information
for this Segment type in Row " _
& myCell.Row & " on the Coding Details Sheet -
PLEASE ENTER ALL DETAILS" _
, 48, "Change Request Form Error Checks"


myCell.Select


Exit For

End If
End If
Next myCell

End With



End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How do I deal with several workbooks that are open in the ActiveWi

You're only going to ever have one worksheet (that belongs to one workbook) in
the Activewindow.

But maybe you could just be more specific:

Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")

becomes:

Set wks = workbooks("myworkbooknamehere.xls") _
.Worksheets("Part B - Coding Details")

or if the code belongs to the workbook that has the data...

Set wks = ThisWorkbook.Worksheets("Part B - Coding Details")



Jacqui wrote:

Can anyone help. The following code falls over if I have other excel files
open in the activewindow. I used to code quite regularly 18 months ago and I
seem to remember there was something to cater for this but I've forgotten
how. Can anyone remind me. Is it that I need to explicitly select my
workbook? See syntax below.
Thanks
Jacqui

Sub Qualifiers_Check()

Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")

With wks

Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))

Set myRng = myRng.Resize(myRng.Count - 1)

For Each myCell In myRng.Cells
If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 5)
If Application.CountA(myRngToCheck) < myRngToCheck.Cells.Count
Then
Beep

Msgbox "You have not supplied all the relevant information
for this Segment type in Row " _
& myCell.Row & " on the Coding Details Sheet -
PLEASE ENTER ALL DETAILS" _
, 48, "Change Request Form Error Checks"


myCell.Select


Exit For

End If
End If
Next myCell

End With


End Sub


--

Dave Peterson
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
Has anyone made a Deal or No Deal Gamebord [email protected] Excel Discussion (Misc queries) 2 April 17th 08 12:12 AM
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM
Workbooks.Open closes other workbooks S. Daum Excel Programming 1 August 21st 03 07:47 PM
Workbooks.Open / .Open Text - How do you stop the .xls addition? Dave[_20_] Excel Programming 2 July 31st 03 04:03 AM


All times are GMT +1. The time now is 06:39 PM.

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"