Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating an event procedure question


I am using the example on Chip Pearson's web page
http://www.cpearson.com/excel/vbe.htm for creating an even procedure in
another workbook for formatting printed output from that workbook.
I have modified his code as follows:


Code:
--------------------
Sub CopytoThisWorkbook()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("BeforePrint", "Workbook") + 1
.InsertLines StartLine, _
" dim NumRows as integer" & vbCr & _
" NumRows = Activesheet.usedrange.rows.count" & vbCr & _
" With Activesheet.pagesetup" & vbCr & _
" .PrintTitleRows = ""$2:$3""" & vbCr & _
" .PrintArea = ""$A$4:$K$"" & NumRows" & vbCr & _
" .PrintHeadings = False" & vbCr & _
" .PrintGridlines = False" & vbCr & _
" .PrintComments = xlPrintNoComments" & vbCr & _
" End With"
End With
End Sub
--------------------


It works as expected and creates the Workbook_BeforePrint procedure.
However whenever the code runs it opens a VBA window and shows the
newly created code. No errors, just gives focus to the VBA window.
This isn't a problem for me while I'm programming/debugging, but the
end user shouldn't see this.

Any ideas why this is happening and how to keep it from happening?

Thanks for any help/suggestions.


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=377417

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Creating an event procedure question

Hi Bhofsetz,

Try inserting:

Application.VBE.MainWindow.Visible = False

before End Sub.


---
Regards,
Norman



"bhofsetz" wrote in
message ...

I am using the example on Chip Pearson's web page
http://www.cpearson.com/excel/vbe.htm for creating an even procedure in
another workbook for formatting printed output from that workbook.
I have modified his code as follows:


Code:
--------------------
Sub CopytoThisWorkbook()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("BeforePrint", "Workbook") + 1
.InsertLines StartLine, _
" dim NumRows as integer" & vbCr & _
" NumRows = Activesheet.usedrange.rows.count" & vbCr & _
" With Activesheet.pagesetup" & vbCr & _
" .PrintTitleRows = ""$2:$3""" & vbCr & _
" .PrintArea = ""$A$4:$K$"" & NumRows" & vbCr & _
" .PrintHeadings = False" & vbCr & _
" .PrintGridlines = False" & vbCr & _
" .PrintComments = xlPrintNoComments" & vbCr & _
" End With"
End With
End Sub
--------------------


It works as expected and creates the Workbook_BeforePrint procedure.
However whenever the code runs it opens a VBA window and shows the
newly created code. No errors, just gives focus to the VBA window.
This isn't a problem for me while I'm programming/debugging, but the
end user shouldn't see this.

Any ideas why this is happening and how to keep it from happening?

Thanks for any help/suggestions.


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile:
http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=377417



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating an event procedure question


Thank you Norman, just what I needed it to do

--
bhofset
-----------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...fo&userid=1880
View this thread: http://www.excelforum.com/showthread.php?threadid=37741

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
Event Procedure Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:29 PM
Event Procedure again Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:28 PM
programming the VBE for a new event procedure mark kubicki Excel Programming 3 August 18th 04 04:43 PM
Event Procedure Programming Jeff Armstrong Excel Programming 1 July 29th 04 03:54 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


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

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"