Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
is is is offline
external usenet poster
 
Posts: 2
Default MacroOptions problem

I'm trying to add a keyboard shortcut for a function I have. I have the
following code in the "ThisWorkbook" 'module':

Option Explicit
Const DATECOL As String = "B"

Public Sub FindToday()
' Keyboard Shortcut: Ctrl+T
Dim r As Range

On Error Resume Next
Set r = ThisWorkbook.Worksheets(1).Range(DATECOL & ":" &
DATECOL).Find(what:=Date, LookIn:=xlValues)
If Not r Is Nothing Then
r.Select
End If
ThisWorkbook.Sheets(1).Activate
End Sub

Public Sub Workbook_Open()
Application.MacroOptions Macro:="FindToday", HasShortcutKey:=True,
ShortcutKey:="t"
FindToday

End Sub

I get:

Run-time error "1004":

Method 'MacroOptions' of object '_Application' failed
<<

I've tried all sorts of things (making the routines public, trying
Macro:=ThisWorkbook.Name & "!" & "FindToday", trying it without
assigning the shortcut key - all fail.

Any suggestions, please?!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 301
Default MacroOptions problem

Put FindToday in its own module, leave the Workbook_Open where it is.
Bob Umlas
Excel MVP

"is" wrote in message
oups.com...
I'm trying to add a keyboard shortcut for a function I have. I have the
following code in the "ThisWorkbook" 'module':

Option Explicit
Const DATECOL As String = "B"

Public Sub FindToday()
' Keyboard Shortcut: Ctrl+T
Dim r As Range

On Error Resume Next
Set r = ThisWorkbook.Worksheets(1).Range(DATECOL & ":" &
DATECOL).Find(what:=Date, LookIn:=xlValues)
If Not r Is Nothing Then
r.Select
End If
ThisWorkbook.Sheets(1).Activate
End Sub

Public Sub Workbook_Open()
Application.MacroOptions Macro:="FindToday", HasShortcutKey:=True,
ShortcutKey:="t"
FindToday

End Sub

I get:

Run-time error "1004":

Method 'MacroOptions' of object '_Application' failed
<<

I've tried all sorts of things (making the routines public, trying
Macro:=ThisWorkbook.Name & "!" & "FindToday", trying it without
assigning the shortcut key - all fail.

Any suggestions, please?!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default MacroOptions problem

You need to put the FindToday macro in a standard code module, not
ThisWorkbook.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"is" wrote in message
oups.com...
I'm trying to add a keyboard shortcut for a function I have. I have the
following code in the "ThisWorkbook" 'module':

Option Explicit
Const DATECOL As String = "B"

Public Sub FindToday()
' Keyboard Shortcut: Ctrl+T
Dim r As Range

On Error Resume Next
Set r = ThisWorkbook.Worksheets(1).Range(DATECOL & ":" &
DATECOL).Find(what:=Date, LookIn:=xlValues)
If Not r Is Nothing Then
r.Select
End If
ThisWorkbook.Sheets(1).Activate
End Sub

Public Sub Workbook_Open()
Application.MacroOptions Macro:="FindToday", HasShortcutKey:=True,
ShortcutKey:="t"
FindToday

End Sub

I get:

Run-time error "1004":

Method 'MacroOptions' of object '_Application' failed
<<

I've tried all sorts of things (making the routines public, trying
Macro:=ThisWorkbook.Name & "!" & "FindToday", trying it without
assigning the shortcut key - all fail.

Any suggestions, please?!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MacroOptions problem

As a minimum,
Move your function to a general module (insert=Module). No a sheet module
or the thisworkbook module.

--
Regards,
Tom Ogilvy


"is" wrote in message
oups.com...
I'm trying to add a keyboard shortcut for a function I have. I have the
following code in the "ThisWorkbook" 'module':

Option Explicit
Const DATECOL As String = "B"

Public Sub FindToday()
' Keyboard Shortcut: Ctrl+T
Dim r As Range

On Error Resume Next
Set r = ThisWorkbook.Worksheets(1).Range(DATECOL & ":" &
DATECOL).Find(what:=Date, LookIn:=xlValues)
If Not r Is Nothing Then
r.Select
End If
ThisWorkbook.Sheets(1).Activate
End Sub

Public Sub Workbook_Open()
Application.MacroOptions Macro:="FindToday", HasShortcutKey:=True,
ShortcutKey:="t"
FindToday

End Sub

I get:

Run-time error "1004":

Method 'MacroOptions' of object '_Application' failed
<<

I've tried all sorts of things (making the routines public, trying
Macro:=ThisWorkbook.Name & "!" & "FindToday", trying it without
assigning the shortcut key - all fail.

Any suggestions, please?!



  #5   Report Post  
Posted to microsoft.public.excel.programming
is is is offline
external usenet poster
 
Posts: 2
Default MacroOptions problem


Tom Ogilvy wrote:

As a minimum,
Move your function to a general module (insert=Module). No a sheet module
or the thisworkbook module.

--
Regards,
Tom Ogilvy



Hurray! Thanks very much guys. A bit embarrassing - I used to know this
stuff! Thanks again.
Cheers!



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
Method 'MacroOptions' of object'_Application' failed Runtime Error 1004 EagleOne Excel Discussion (Misc queries) 1 October 22nd 14 05:49 PM
Trouble With MacroOptions Sprinks Excel Programming 2 December 27th 05 05:51 PM
MacroOptions Method Dave Excel Programming 0 November 14th 05 01:07 PM
MacroOptions doesn't stick Greg Lovern[_3_] Excel Programming 5 April 11th 05 06:18 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


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

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"