Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Debug code in workbook open or activate events

Hi all,

How can debug code in workbook open or activate event

Clara
--
thank you so much for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Debug code in workbook open or activate events

Clara,

To debug the workbook open event, you can use the Stop statement at the
point where you want to start debugging. For example:

Private Sub Workbook_Open()

Stop 'this will suspend code execution and open the debugger. like
setting a breakpoint.

'your code here..
MsgBox "Hello, World"

End Sub

Save and close the workbook. Then re-open it. When the workbook open code
executes, it will suspend execution at the point where you put the Stop
statement and take you to the VBE.

To debug the activate event, you can use breakpoints. In the VBE, put the
cursor on the line of code where you want to start debugging, then press F9.
Go to the Excel application window and switch to a different workbook then
back again to the one you want to debug and it will trigger the activate
event.



--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi all,

How can debug code in workbook open or activate event

Clara
--
thank you so much for your help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 461
Default Debug code in workbook open or activate events

Go to the VBE

Look at the Project explorer to the left. It shows your workbooks in a tree
like formation.

Find the sheet if it is a Worksheet event and double click the sheet...
If it is a workbook event, double click the workbook icon.

This should atleast bring up the code... then go through the code by
pressing F8 to see where you get your problem.

"clara" wrote:

Hi all,

How can debug code in workbook open or activate event

Clara
--
thank you so much for your help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Debug code in workbook open or activate events

Courtesy of Randy Birch

Option Explicit

Private Declare Function SQLDataSources Lib "odbc32.dll" _
(ByVal hEnv As Long, _
ByVal fDirection As Integer, _
ByVal szDSN As String, _
ByVal cbDSNMax As Integer, _
pcbDSN As Integer, _
ByVal szDescription As String, _
ByVal cbDescriptionMax As Integer, _
pcbDescription As Integer) As Long

Private Declare Function SQLAllocHandle Lib "odbc32.dll" _
(ByVal HandleType As Integer, _
ByVal InputHandle As Long, _
OutputHandlePtr As Long) As Long

Private Declare Function SQLSetEnvAttr Lib "odbc32.dll" _
(ByVal EnvironmentHandle As Long, _
ByVal dwAttribute As Long, _
ByVal ValuePtr As Long, _
ByVal StringLen As Long) As Long

Private Declare Function SQLFreeHandle Lib "odbc32.dll" _
(ByVal HandleType As Integer, _
ByVal Handle As Long) As Long

Private Const SQL_MAX_DSN_LENGTH As Long = 32
Private Const SQL_MAX_DESC_LENGTH As Long = 128
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_FETCH_NEXT As Long = 1
Private Const SQL_NULL_HANDLE As Long = 0
Private Const SQL_HANDLE_ENV As Long = 1
Private Const SQL_ATTR_ODBC_VERSION As Long = 200
Private Const SQL_OV_ODBC3 As Long = 3
Private Const SQL_IS_INTEGER As Long = (-6)

Private Sub GetUserSystemDSN()
Dim hEnv As Long
Dim sServer As String
Dim sDriver As String
Dim nSvrLen As Integer
Dim nDvrLen As Integer
Dim lstDSNs As String

If SQLAllocHandle(SQL_HANDLE_ENV, _
SQL_NULL_HANDLE, hEnv) < 0 Then

If SQLSetEnvAttr(hEnv, _
SQL_ATTR_ODBC_VERSION, _
SQL_OV_ODBC3, _
SQL_IS_INTEGER) < 0 Then


sServer = Space$(SQL_MAX_DSN_LENGTH)

Do While SQLDataSources(hEnv, _
SQL_FETCH_NEXT, _
sServer, _
SQL_MAX_DSN_LENGTH, _
nSvrLen, _
sDriver, _
SQL_MAX_DESC_LENGTH, _
nDvrLen) = SQL_SUCCESS

lstDSNs = lstDSNs & Left$(sServer, nSvrLen) & vbNewLine

sServer = Space$(SQL_MAX_DSN_LENGTH)

Loop

End If 'If SQLSetEnvAttr

Call SQLFreeHandle(SQL_HANDLE_ENV, hEnv)

End If 'If SQLAllocHandle

MsgBox lstDSNs

End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"clara" wrote in message
...
Hi all,

How can debug code in workbook open or activate event

Clara
--
thank you so much for your help



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Debug code in workbook open or activate events

I guess this was for the enumerate DSN question.

--
Regards,
Tom Ogilvy


"Bob Phillips" wrote:

Courtesy of Randy Birch

Option Explicit

Private Declare Function SQLDataSources Lib "odbc32.dll" _
(ByVal hEnv As Long, _
ByVal fDirection As Integer, _
ByVal szDSN As String, _
ByVal cbDSNMax As Integer, _
pcbDSN As Integer, _
ByVal szDescription As String, _
ByVal cbDescriptionMax As Integer, _
pcbDescription As Integer) As Long

Private Declare Function SQLAllocHandle Lib "odbc32.dll" _
(ByVal HandleType As Integer, _
ByVal InputHandle As Long, _
OutputHandlePtr As Long) As Long

Private Declare Function SQLSetEnvAttr Lib "odbc32.dll" _
(ByVal EnvironmentHandle As Long, _
ByVal dwAttribute As Long, _
ByVal ValuePtr As Long, _
ByVal StringLen As Long) As Long

Private Declare Function SQLFreeHandle Lib "odbc32.dll" _
(ByVal HandleType As Integer, _
ByVal Handle As Long) As Long

Private Const SQL_MAX_DSN_LENGTH As Long = 32
Private Const SQL_MAX_DESC_LENGTH As Long = 128
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_FETCH_NEXT As Long = 1
Private Const SQL_NULL_HANDLE As Long = 0
Private Const SQL_HANDLE_ENV As Long = 1
Private Const SQL_ATTR_ODBC_VERSION As Long = 200
Private Const SQL_OV_ODBC3 As Long = 3
Private Const SQL_IS_INTEGER As Long = (-6)

Private Sub GetUserSystemDSN()
Dim hEnv As Long
Dim sServer As String
Dim sDriver As String
Dim nSvrLen As Integer
Dim nDvrLen As Integer
Dim lstDSNs As String

If SQLAllocHandle(SQL_HANDLE_ENV, _
SQL_NULL_HANDLE, hEnv) < 0 Then

If SQLSetEnvAttr(hEnv, _
SQL_ATTR_ODBC_VERSION, _
SQL_OV_ODBC3, _
SQL_IS_INTEGER) < 0 Then


sServer = Space$(SQL_MAX_DSN_LENGTH)

Do While SQLDataSources(hEnv, _
SQL_FETCH_NEXT, _
sServer, _
SQL_MAX_DSN_LENGTH, _
nSvrLen, _
sDriver, _
SQL_MAX_DESC_LENGTH, _
nDvrLen) = SQL_SUCCESS

lstDSNs = lstDSNs & Left$(sServer, nSvrLen) & vbNewLine

sServer = Space$(SQL_MAX_DSN_LENGTH)

Loop

End If 'If SQLSetEnvAttr

Call SQLFreeHandle(SQL_HANDLE_ENV, hEnv)

End If 'If SQLAllocHandle

MsgBox lstDSNs

End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"clara" wrote in message
...
Hi all,

How can debug code in workbook open or activate event

Clara
--
thank you so much for your help




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't seem to activate an open workbook dantee Excel Discussion (Misc queries) 1 July 11th 08 02:48 AM
how to Activate the previous Open, workbook..? acegap Excel Programming 3 June 25th 06 04:14 PM
Get in DEBUG mode on workbook open Anthony Fok[_2_] Excel Programming 5 July 28th 05 06:30 PM
open and activate workbook? Dave Peterson[_3_] Excel Programming 0 June 30th 04 03:07 AM
Deactive Activate Workbook Events - Add Menu jamiee Excel Programming 1 February 14th 04 08:43 PM


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