Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Wait for 'Print' or 'Close' (VBA)


I've got code that includes importing data from solidworks and printing
multiple sheets. since things can tend to be wrong, i'd like the code
to bring up the print preview for a sheet, wait for the user to either
hit 'Close' or 'Print' and then continue to the next sheet...

any time i leave the preview open for more than about 10 seconds i get
a popup complaining that the server's busy, and i have the options of
'switch to' and 'retry.

i really want to get rid of this window, and it's only coming up
because the print preview is waiting for user input.

is there a property like 'WorksheetIsCurrentlyInPrintPreview' that i
could flag?

is there an event trigger that i could use? 'OnPrint'? or
'OnClosePrintPreview'?

any advice at all?


--
Milothicus
------------------------------------------------------------------------
Milothicus's Profile: http://www.excelforum.com/member.php...o&userid=15121
View this thread: http://www.excelforum.com/showthread...hreadid=378923

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Wait for 'Print' or 'Close' (VBA)


ok, think i'm getting closer already...

i found this event:

Private Sub Workbook_BeforePrint(Cancel As Boolean)

End Sub

now i need some more help. If i use a boolean in my solidworks macro,
how do I change its state from the code in this module? is it possible?


--
Milothicus
------------------------------------------------------------------------
Milothicus's Profile: http://www.excelforum.com/member.php...o&userid=15121
View this thread: http://www.excelforum.com/showthread...hreadid=378923

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Need to Wait for 'Print' or 'Close' (VBA)

Roedd <<Milothicus wedi ysgrifennu:

I've got code that includes importing data from solidworks and
printing multiple sheets. since things can tend to be wrong, i'd like
the code to bring up the print preview for a sheet, wait for the user
to either hit 'Close' or 'Print' and then continue to the next
sheet...

any time i leave the preview open for more than about 10 seconds i get
a popup complaining that the server's busy, and i have the options of
'switch to' and 'retry.

i really want to get rid of this window, and it's only coming up
because the print preview is waiting for user input.

is there a property like 'WorksheetIsCurrentlyInPrintPreview' that i
could flag?

is there an event trigger that i could use? 'OnPrint'? or
'OnClosePrintPreview'?



It looks like you're connecting to solidworks (which I'm not familiar with)
via COM/OLE automation In that case, you can turn off OLE messages like
this:

Private Declare Function _
CoRegisterMessageFilter Lib "OLE32.DLL" _
(ByVal lFilterIn As Long, _
ByRef lPreviousFilter) As Long

Sub KillMessageFilter()

Dim lngMsgFilter As Long

''' Remove the message filter before
''' calling the COM server.
CoRegisterMessageFilter 0&, lngMsgFilter

''' Call the COM server here....

''' Restore the message filter after
''' calling the COM server.
CoRegisterMessageFilter lngMsgFilter, _
lngMsgFilter

End Sub

--
Rob

http://www.asta51.dsl.pipex.com/webcam/

This message is copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Wait for 'Print' or 'Close' (VBA)


well, the macro is initiated in Solidworks, and it's all written in VBA.
I do some work in Solidworks, save info to an array, and then use
excel's API to open a spreadsheet and place the info into excel.

I'm not a complete newbie, but i'm not sure what COM/OLE automation is.
I'm just using VBA to move between the two of them. maybe that's what i
need, but i can't make sense of what you've suggested... i don't know
which section of my code would replace 'Call the COM server here...'

The code for the macro is in an .swp file (solidworks program), and the
event i mentioned above is attached to the workbook. there must be a way
to use the event in the workbook code to set a variable to 'true' in the
solidworks code.

could i send keystrokes with one to be received by the other?


--
Milothicus
------------------------------------------------------------------------
Milothicus's Profile: http://www.excelforum.com/member.php...o&userid=15121
View this thread: http://www.excelforum.com/showthread...hreadid=378923

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Need to Wait for 'Print' or 'Close' (VBA)

Roedd <<Milothicus wedi ysgrifennu:

well, the macro is initiated in Solidworks, and it's all written in
VBA. I do some work in Solidworks, save info to an array, and then use
excel's API to open a spreadsheet and place the info into excel.

I'm not a complete newbie, but i'm not sure what COM/OLE automation
is. I'm just using VBA to move between the two of them. maybe that's
what i need, but i can't make sense of what you've suggested... i
don't know which section of my code would replace 'Call the COM
server here...'

The code for the macro is in an .swp file (solidworks program),


OK. It looks like you're doing COM automation without knowing it. Stick it
on your CV.

Put the declaration (Private Declare Function etc.) at the top of a regular
bas module. If you are going to call it from a different module, change the
declaration from Private to Public.

Now, find where you are starting up your Excel instance (either set
[variable] = new Excel.Application or CreateObject(...). Put the line

CoRegisterMessageFilter 0&, lngMsgFilter

just before it. Now find where you are destroying your Excel instance
([variable].Quit: set Excel = nothing) and put the line

CoRegisterMessageFilter lngMsgFilter, lngMsgFilter

just after it. You will also need to declare the lngMsgFilter variable in
your routine. This will stop the message appearing when solidworks thinks
that Excel has stopped responding. You could experiment with putting these
lines just before and after where you call the printpreview if you are
worried about loosing all messages should Excel hang for another reason.

the event i mentioned above is attached to the workbook. there must
be a way to use the event in the workbook code to set a variable to
'true' in the solidworks code.


There is, but I don't think it would help, since the message you are seeing
is raised from deep under the hood.

could i send keystrokes with one to be received by the other?


Don't do that.

--
Rob

http://www.asta51.dsl.pipex.com/webcam/

This message is copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Wait for 'Print' or 'Close' (VBA)


Robert Bruce Wrote:
Roedd <<Milothicus wedi ysgrifennu:
OK. It looks like you're doing COM automation without knowing it. Stick
it
on your CV.

Woohoo! i have job skills!


Put the declaration (Private Declare Function etc.) at the top of a
regular
bas module. If you are going to call it from a different module, change
the
declaration from Private to Public.

Now, find where you are starting up your Excel instance (either set
[variable] = new Excel.Application or CreateObject(...). Put the line

CoRegisterMessageFilter 0&, lngMsgFilter

just before it. Now find where you are destroying your Excel instance
([variable].Quit: set Excel = nothing) and put the line

CoRegisterMessageFilter lngMsgFilter, lngMsgFilter

just after it. You will also need to declare the lngMsgFilter variable
in
your routine. This will stop the message appearing when solidworks
thinks
that Excel has stopped responding. You could experiment with putting
these
lines just before and after where you call the printpreview if you are
worried about loosing all messages should Excel hang for another
reason.


the event i mentioned above is attached to the workbook.

there must
be a way to use the event in the workbook code to set a variable to
'true' in the solidworks code.


There is, but I don't think it would help, since the message you are
seeing
is raised from deep under the hood.

Fair enough.

could i send keystrokes with one to be received by the

other?
Don't do that.

I'll avoid it like the plague.

Thanks for the help. your explanation makes sense to me now. so does
your suggestion just apply a filter to messages that doesn't allow any
through?



--
Milothicus
------------------------------------------------------------------------
Milothicus's Profile: http://www.excelforum.com/member.php...o&userid=15121
View this thread: http://www.excelforum.com/showthread...hreadid=378923

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Wait for 'Print' or 'Close' (VBA)


Works like a charm. Thanks

--
Milothicu
-----------------------------------------------------------------------
Milothicus's Profile: http://www.excelforum.com/member.php...fo&userid=1512
View this thread: http://www.excelforum.com/showthread.php?threadid=37892

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
sendkeys(keys,wait) how do I use wait MM Excel Discussion (Misc queries) 1 February 11th 09 03:47 PM
Print before close Renato8 Excel Discussion (Misc queries) 2 April 28th 06 09:03 PM
how to close print preview Lou Allen Excel Worksheet Functions 1 July 24th 05 03:39 AM
Open, print and close workbook despistado[_4_] Excel Programming 0 November 12th 04 07:51 AM
Open, print and close workbook despistado Excel Programming 1 November 11th 04 10:47 AM


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