Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Jan Karel Pieterse-print preview

thanks for teh response!!!!

i am glad that you see that when someone is in the print preview mode
then no macros run.

i was thinking that if i can capture the event of clicking print
preview then i could see that the user has clicked it so i could give
him a point.


can you expand a bit on the SetTimer API suggestion.



how it works and where can i find additional info?

thanks a lot in advance.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Jan Karel Pieterse-print preview

Hi nikolaosk

can you expand a bit on the SetTimer API suggestion.


You can use this API function to start a timer that will fire a
subroutine in your code on a set interval.

BUT IT WILL DO SO REGARDLESS OF EXCEL'S STATE!!

This means that actions the macro will try to do which are normally
forbidden in that state may crash Excel.

This code may be an example of how to use the timer API:

Option Explicit

'API Declarations

Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long

Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long

Declare Function GetCurrentVbaProject Lib "vba332.dll" _
Alias "EbGetExecutingProj" _
(hProject As Long) As Long
Declare Function GetFuncID Lib "vba332.dll" Alias "TipGetFunctionId" _
(ByVal hProject As Long, ByVal
strFunctionName As String, _
ByRef strFunctionId As String) As Long
Declare Function GetAddr Lib "vba332.dll" Alias
"TipGetLpfnOfFunctionId" _
(ByVal hProject As Long, ByVal
strFunctionId As String, _
ByRef lpfn As Long) As Long
' Public Variables

Public SecondCtr As Integer
Public TimerID As Long
Public bTimerState As Boolean
Public Const lTime as long=10 'every 10 minutes

Sub TimerOn()
If bTimerState = False Then
If Left(Application.Version, 1) = "8" Then
TimerID = SetTimer(0, 0, lTime * 60000, AddrOf("YourSub"))
Else
TimerID = SetTheTimer2K
End If
If TimerID = 0 Then
MsgBox "Unable to create the timer", vbCritical +
vbOKOnly, "Error"
Exit Sub
End If
bTimerState = True
End If
End Sub

Sub TimerOff()
If bTimerState = True Then
TimerID = KillTimer(0, TimerID)
If TimerID = 0 Then
MsgBox "Unable to stop the timer", vbCritical + vbOKOnly,
"Error"
End If
bTimerState = False
End If
End Sub


Public Function AddrOf(strFuncName As String) As Long
'Returns a function pointer of a VBA public function given its name.
'AddrOf code from Microsoft Office Developer magazine
'http://www.informant.com/mod/index.htm
Dim hProject As Long
Dim lngResult As Long
Dim strID As String
Dim lpfn As Long
Dim strFuncNameUnicode As String
Const NO_ERROR = 0
' The function name must be in Unicode, so convert it.
strFuncNameUnicode = StrConv(strFuncName, vbUnicode)
' Get the current VBA project
Call GetCurrentVbaProject(hProject)
' Make sure we got a project handle
If hProject < 0 Then
' Get the VBA function ID
lngResult = GetFuncID(hProject, strFuncNameUnicode, strID)
If lngResult = NO_ERROR Then
' Get the function pointer.
lngResult = GetAddr(hProject, strID, lpfn)
If lngResult = NO_ERROR Then
AddrOf = lpfn
End If
End If
End If
End Function

Function SetTheTimer2K()
SetTheTimer2K = SetTimer(0, 0, lTime * 60000, AddressOf YourSub)
End Function

Regards,

Jan Karel Pieterse
Excel MVP
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
Plot Area Automatically Expands in Print and Print Preview Myk D. Charts and Charting in Excel 2 March 12th 09 01:41 PM
First page of Excel sheerepeats in print layout or print preview philfrotonda Excel Discussion (Misc queries) 1 July 12th 07 09:28 PM
Print and Print Preview Graphic Moving Resizing 2007/2003 Adam Rayburn Excel Discussion (Misc queries) 0 April 4th 07 04:18 PM
print preview v page break preview SamB Excel Discussion (Misc queries) 0 November 16th 06 05:09 PM
cell borders that I create dont show on print preview or print scott3435 Excel Discussion (Misc queries) 2 April 6th 06 02:37 AM


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