Solved

Worksheet Preview Doesn't Get Focus... vb6

Posted on 2004-09-17
7
396 Views
Last Modified: 2012-06-21
Using this code from a vb 6 form (with selected workbook already open):

Set xlApp = GetObject(,"Excel.Application")        '<-- locates excel application
Set xlWkBk = xlApp.Workbooks(strFile)              '<-- locates workbook strFile in the excel application
Set xlWs = xlWkBk.WorkSheets(StrWs)             '<-- locates worksheet StrWs in the workbook strFile
xlWkBk.Activate                                        '<-- activate the workbook (I am not sure if this is necessary)
xlWs.Select                                              '<-- select the worksheet (I am not sure if this is necessary)
xlApp.WindowsState = xlMinimized            '<-- this minimizes the application, not to block the previewed worksheet
                                                              '      I have tried with and without this line of code.
xlws.PrintPreview           '<-- the worksheet in preview stays minimized in task bar but blinking

I need above code to be revised such that the previewed worksheet would popup and the user dosn't have to click on it to bring it up.

Thanks.
0
Comment
Question by:Mike Eghtebas
  • 4
  • 3
7 Comments
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 250 total points
ID: 12086136
I'm not sure but I think it's because Windows prevents a minimized window restoring with anything less than user input.  The flashing bar suggests that the window has updated but is not restoring.  

Can you use
     xlApp.WindowState = vbNormal

to restore the window to its original position?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12086346
As you can see, I have tried both with and without "xlApp.WindowsState = xlMinimized".

When I exclude it, still previewed worksheet shows in the taskbar only (blinking) with the workbook in Noraml state.

But, when I use it, the workbook gets out of the way, but the previewed worksheet in another xl logo on the taskbar keeps blinking.  

All I want to eliminate the need for an extra (and unnecessary click) by the user to bring up the previewed worksheet.

I will try "xlApp.WindowState = vbNormal" at the end of the code.  But I am not sure what will be restored (the workbook or the previewed worksheet?).  Do we have code to make sure the previewed workssheet is restored not the workbook?

(I have to do the test in another computer, brb)

Mike
, now, what I will do

0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12086450
Correction...

Previwed worksheet doesn't appear separately in the taskbar as I have said in my last post.  On can see the workbook itself only after the previewed worksheet is accessed and closed.

xlApp.WindowState = vbNormal didn't help.  Is there a code like:

xlApp.<WindowPreviewedState> = vbNormal    ?

---------
sorry about extra line after my name in the last post.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12086810
I guess this problem is caused by bad use of some other code.  I will post my findings shortly.  It seems it has to do with use of GetObject and CreatObject as discussed in:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21133116.html

I will post my findings shortly.
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12101058
How are you calling this routine?  I tried the above code from a button and it failed on the xlApp.WindowState = vbMinimized line.  However, when I commented this line out, the print preview opened.  When I clicked 'Close' on the print preview screen, it disappeared and the worksheet came back.

What are you trying to eliminate; the need to click 'Close'?
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12101069
...or are you trying to PP one workbook from within another, before returning control to the first?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12103807
The correct syntax was:

    Set xlWs = xlWkBk.Worksheets(WsName)                ' Set it to the desired workbook
   
    xlApp.Visible = True
    xlWkBk.Activate       '<-- this may not be necessary
    xlWs.Select
    Application.WindowState = xlNormal
    xlWs.PrintPreview

                                     
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now