Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 67
Default Macro to fire upon opening file

I have a shared workbook that I would like a macro to begin upon opening it
that will do the following:

Select sheet "Cathy"
Find cell with the value "This"
Hit home key (to place the cursor at the first column location)
Do the same for sheets named "Gus", "Ed H", "Chris", "Shutter", "Carpet".

Many thanks for your help.

--
David P.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to fire upon opening file

Option Explicit
Sub Auto_Open()

Dim mySheetNames As Variant
Dim sCtr As Long
Dim FoundCell As Range
Dim wks As Worksheet

mySheetNames = Array("Cathy", "Gus", "Ed H", "Chris", "Shutter", "Carpet")

For sCtr = LBound(mySheetNames) To UBound(mySheetNames)
Set wks = Nothing
On Error Resume Next
Set wks = Worksheets(mySheetNames(sCtr))
On Error GoTo 0

If wks Is Nothing Then
'do nothing
Else
With wks
Set FoundCell = .Cells.Find(what:="This", _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'do nothing
Else
Application.Goto FoundCell.EntireRow.Cells(1), scroll:=True
End If
End With
End If
Next sCtr
End Sub

David P. wrote:

I have a shared workbook that I would like a macro to begin upon opening it
that will do the following:

Select sheet "Cathy"
Find cell with the value "This"
Hit home key (to place the cursor at the first column location)
Do the same for sheets named "Gus", "Ed H", "Chris", "Shutter", "Carpet".

Many thanks for your help.

--
David P.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 67
Default Macro to fire upon opening file

Dave. It worked like a charm as I expected. Your replies are always fantastic
and invaulable.

Can I ask you one more question for a completely different workbook? If I
wanted to do the exact same thing except with the following changes what
would the code be?:

Select sheet "Messages"
Find cell with the value "Today."
Hit home key (to place the cursor at the first column location)
(This time this is the only sheet I need this done for)

--
David P.


"Dave Peterson" wrote:

Option Explicit
Sub Auto_Open()

Dim mySheetNames As Variant
Dim sCtr As Long
Dim FoundCell As Range
Dim wks As Worksheet

mySheetNames = Array("Cathy", "Gus", "Ed H", "Chris", "Shutter", "Carpet")

For sCtr = LBound(mySheetNames) To UBound(mySheetNames)
Set wks = Nothing
On Error Resume Next
Set wks = Worksheets(mySheetNames(sCtr))
On Error GoTo 0

If wks Is Nothing Then
'do nothing
Else
With wks
Set FoundCell = .Cells.Find(what:="This", _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'do nothing
Else
Application.Goto FoundCell.EntireRow.Cells(1), scroll:=True
End If
End With
End If
Next sCtr
End Sub

David P. wrote:

I have a shared workbook that I would like a macro to begin upon opening it
that will do the following:

Select sheet "Cathy"
Find cell with the value "This"
Hit home key (to place the cursor at the first column location)
Do the same for sheets named "Gus", "Ed H", "Chris", "Shutter", "Carpet".

Many thanks for your help.

--
David P.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to fire upon opening file

You can make just a couple of minor changes to the existing code:

mySheetNames = Array("Cathy", "Gus", "Ed H", "Chris", "Shutter", "Carpet")

and this line
Set FoundCell = .Cells.Find(what:="This", _


become:

mySheetNames = Array("Messages")

and this line
Set FoundCell = .Cells.Find(what:="today", _


Using an array is probably overkill--why loop when there's only one item?

'Cause it's the easiest change! <vbg

David P. wrote:

Dave. It worked like a charm as I expected. Your replies are always fantastic
and invaulable.

Can I ask you one more question for a completely different workbook? If I
wanted to do the exact same thing except with the following changes what
would the code be?:

Select sheet "Messages"
Find cell with the value "Today."
Hit home key (to place the cursor at the first column location)
(This time this is the only sheet I need this done for)

--
David P.

"Dave Peterson" wrote:

Option Explicit
Sub Auto_Open()

Dim mySheetNames As Variant
Dim sCtr As Long
Dim FoundCell As Range
Dim wks As Worksheet

mySheetNames = Array("Cathy", "Gus", "Ed H", "Chris", "Shutter", "Carpet")

For sCtr = LBound(mySheetNames) To UBound(mySheetNames)
Set wks = Nothing
On Error Resume Next
Set wks = Worksheets(mySheetNames(sCtr))
On Error GoTo 0

If wks Is Nothing Then
'do nothing
Else
With wks
Set FoundCell = .Cells.Find(what:="This", _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'do nothing
Else
Application.Goto FoundCell.EntireRow.Cells(1), scroll:=True
End If
End With
End If
Next sCtr
End Sub

David P. wrote:

I have a shared workbook that I would like a macro to begin upon opening it
that will do the following:

Select sheet "Cathy"
Find cell with the value "This"
Hit home key (to place the cursor at the first column location)
Do the same for sheets named "Gus", "Ed H", "Chris", "Shutter", "Carpet".

Many thanks for your help.

--
David P.


--

Dave Peterson


--

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
Can a macro be run on opening the file? Cortez Excel Discussion (Misc queries) 3 March 8th 07 08:34 PM
Can a macro be run on opening the file? Cortez Excel Discussion (Misc queries) 0 March 8th 07 04:57 PM
Fire Macro from Cell Change Slashman Excel Worksheet Functions 7 October 17th 06 04:08 AM
Data Val list Excel 97 fire macro rgarber50 Excel Discussion (Misc queries) 4 October 9th 05 05:19 PM
Opening a file with a Macro Adam1 Chicago Excel Discussion (Misc queries) 2 February 28th 05 10:13 PM


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

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

About Us

"It's about Microsoft Excel"