PC Review


Reply
Thread Tools Rate Thread

Activate a Workbook

 
 
Bishop
Guest
Posts: n/a
 
      28th May 2009
I have this code:

For Each wb In Workbooks
'Test to see if wb's name is like "*C&A PF*.xlsm"
If wb.Name Like "*C&A PF*.xlsm" Then
???.Activate
End If
Next

How do I make THAT workbook the active workbook?
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      28th May 2009
There is no need to activate the sheets or the workbook. Just use wb instead
of the workbook name


For Each wb In Workbooks
'Test to see if wb's name is like "*C&A PF*.xlsm"
If wb.Name Like "*C&A PF*.xlsm" Then
with wb
.sheets("Sheet1").Range("A1") = "ABC"
end wb
End If
Next


"Bishop" wrote:

> I have this code:
>
> For Each wb In Workbooks
> 'Test to see if wb's name is like "*C&A PF*.xlsm"
> If wb.Name Like "*C&A PF*.xlsm" Then
> ???.Activate
> End If
> Next
>
> How do I make THAT workbook the active workbook?

 
Reply With Quote
 
Bishop
Guest
Posts: n/a
 
      29th May 2009
I see what you're doing when I try that I still get another error. Here's my
code:

For Each wb In Workbooks
'Test to see if wb's name is like "*C&A PF*.xlsm"
If wb.Name Like "*C&A PF*.xlsm" Then
With wb
Set CDLastRow = .Sheets("Catalyst Dump").Range("A" &
Rows.Count) _
& .End(xlUp).Row
.Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 18
End With
End If
Next

I've tried:
Set CDLastRow = but this gives Object Required error
CDLastRow = but this gives RT Error: '438' Object doesn't support property
or method
CDLastRow = .Worksheets still 438

I can't figure it out.

"Joel" wrote:

> There is no need to activate the sheets or the workbook. Just use wb instead
> of the workbook name
>
>
> For Each wb In Workbooks
> 'Test to see if wb's name is like "*C&A PF*.xlsm"
> If wb.Name Like "*C&A PF*.xlsm" Then
> with wb
> .sheets("Sheet1").Range("A1") = "ABC"
> end wb
> End If
> Next
>
>
> "Bishop" wrote:
>
> > I have this code:
> >
> > For Each wb In Workbooks
> > 'Test to see if wb's name is like "*C&A PF*.xlsm"
> > If wb.Name Like "*C&A PF*.xlsm" Then
> > ???.Activate
> > End If
> > Next
> >
> > How do I make THAT workbook the active workbook?

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      29th May 2009
Check your other post.

Bishop wrote:
>
> I see what you're doing when I try that I still get another error. Here's my
> code:
>
> For Each wb In Workbooks
> 'Test to see if wb's name is like "*C&A PF*.xlsm"
> If wb.Name Like "*C&A PF*.xlsm" Then
> With wb
> Set CDLastRow = .Sheets("Catalyst Dump").Range("A" &
> Rows.Count) _
> & .End(xlUp).Row
> .Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 18
> End With
> End If
> Next
>
> I've tried:
> Set CDLastRow = but this gives Object Required error
> CDLastRow = but this gives RT Error: '438' Object doesn't support property
> or method
> CDLastRow = .Worksheets still 438
>
> I can't figure it out.
>
> "Joel" wrote:
>
> > There is no need to activate the sheets or the workbook. Just use wb instead
> > of the workbook name
> >
> >
> > For Each wb In Workbooks
> > 'Test to see if wb's name is like "*C&A PF*.xlsm"
> > If wb.Name Like "*C&A PF*.xlsm" Then
> > with wb
> > .sheets("Sheet1").Range("A1") = "ABC"
> > end wb
> > End If
> > Next
> >
> >
> > "Bishop" wrote:
> >
> > > I have this code:
> > >
> > > For Each wb In Workbooks
> > > 'Test to see if wb's name is like "*C&A PF*.xlsm"
> > > If wb.Name Like "*C&A PF*.xlsm" Then
> > > ???.Activate
> > > End If
> > > Next
> > >
> > > How do I make THAT workbook the active workbook?


--

Dave Peterson
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      29th May 2009
You are using the aphersand and SET incorrectly

Set CDLastRow = .Sheets("Catalyst Dump").Range("A" &
Rows.Count) _
& .End(xlUp).Row

1) The line should be

CDLastRow = .Sheets("Catalyst Dump").Range("A" & Rows.Count).End(xlUp).Row

2) The & is used to combine two strings like this

a = "Boys"
b = "and"
c = "Girls"

d = a & b & c 'this is "Boys and Girls"

3) The underscore is a line continuation character

You can't do this

& .End(xlUp).Row

The amphsand is wrong

4) You don't neet to have the wrod set since you are returning the ".ROW"
which is a number and not an object.

instead of this
CDLastRow = .Sheets("Catalyst Dump").Range("A" & Rows.Count).End(xlUp).Row

you can do this

set CDLastRow = .Sheets("Catalyst Dump").Range("A" & Rows.Count).End(xlUp)

CDLastRow is the actual last cell (an object) in the above. My original
code is returning a number.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I open an Excel Workbook from Outlook macro and activate that workbook? Damil4real Microsoft Excel Discussion 1 25th Jan 2011 04:56 AM
Workbook activate help dgold82 Microsoft Excel Programming 6 3rd Aug 2009 01:38 AM
Workbook.Activate / Window.Activate problem Tim Microsoft Excel Programming 3 3rd Feb 2006 11:38 PM
Activate workbook =?Utf-8?B?VGltVA==?= Microsoft Excel Programming 5 29th Nov 2005 08:41 PM
Calling a Personal.XLS Sub from anther workbook's 'This Workbook' Sheet Activate Jack Gillis Microsoft Excel Discussion 2 21st Mar 2005 11:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:41 PM.