Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to Remove Workbook_Open macro?


I have a Workbook_Open macro which is only required when the document is
opened for the first time by a user. I want to have it remove itself
after running. I suspect the answer lies in removing a VBComponent but
I don't know how to tackle this.

Can anyone help? Point me in the right direction?

Thanks.


--
ANDYGM
------------------------------------------------------------------------
ANDYGM's Profile: http://www.excelforum.com/member.php...fo&userid=3452
View this thread: http://www.excelforum.com/showthread...hreadid=532200

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to Remove Workbook_Open macro?

'-----------------------------------------------------------------
Private Sub Workbook_Open()
'-----------------------------------------------------------------

MsgBox "This procedure runs once only"

Dim oCodeModule As Object
Dim iStart As Long
Dim cLines As Long

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
With oCodeModule
iStart = .ProcStartLine("Workbook_Open", 0)
cLines = .ProcCountLines("Workbook_Open", 0)
.DeleteLines iStart, cLines
On Error GoTo 0
Exit Sub
End With


End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"ANDYGM" wrote in
message ...

I have a Workbook_Open macro which is only required when the document is
opened for the first time by a user. I want to have it remove itself
after running. I suspect the answer lies in removing a VBComponent but
I don't know how to tackle this.

Can anyone help? Point me in the right direction?

Thanks.


--
ANDYGM
------------------------------------------------------------------------
ANDYGM's Profile:

http://www.excelforum.com/member.php...fo&userid=3452
View this thread: http://www.excelforum.com/showthread...hreadid=532200



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default How to Remove Workbook_Open macro?

Rather than writing complex code to edit code modules, why not just save a
registry value the first time the macro is run successfully, and have the
macro check for this variable when the workbook is opened.

Robin Hammond
www.enhanceddatasystems.com

"ANDYGM" wrote in
message ...

I have a Workbook_Open macro which is only required when the document is
opened for the first time by a user. I want to have it remove itself
after running. I suspect the answer lies in removing a VBComponent but
I don't know how to tackle this.

Can anyone help? Point me in the right direction?

Thanks.


--
ANDYGM
------------------------------------------------------------------------
ANDYGM's Profile:
http://www.excelforum.com/member.php...fo&userid=3452
View this thread: http://www.excelforum.com/showthread...hreadid=532200



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to Remove Workbook_Open macro?


Great! I used the code and it worked perfectly. Thanks.


--
ANDYGM
------------------------------------------------------------------------
ANDYGM's Profile: http://www.excelforum.com/member.php...fo&userid=3452
View this thread: http://www.excelforum.com/showthread...hreadid=532200

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
Workbook_Open macro not running mrice Excel Discussion (Misc queries) 2 April 26th 06 06:45 PM
Workbook_Open macro - what gives? Geoff C Excel Programming 5 March 9th 05 01:27 PM
Help with Workbook_Open macro please Geoff C Excel Programming 7 January 13th 05 10:19 AM
Prevent Workbook_Open macro big t Excel Programming 2 August 20th 04 12:01 PM
Workbook_Open & Macro James Cox[_2_] Excel Programming 0 July 2nd 04 03:44 PM


All times are GMT +1. The time now is 09:34 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"