Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Prview Worksheet using VB 6... Component Request Pending...

Posted on 2004-08-09
1
Medium Priority
?
439 Views
Last Modified: 2008-02-01
I have this code to preview worksheet 'Sheet1' (code in VB 6 environment):

Dim xlApp As New Excel.Application
Dim xlWkBk As Excel.Workbook
Dim xlWkSht As Excel.Worksheet

Set xlWkBk = xlApp.Workbooks.Open("C:\MyFolder\Test.xls")
Set xlWkSht = xlWkBk.Worksheets("Sheet1")
xlWkSht.PrintPreview     <--- error here

Set xlWkSht = Nothing
xlWkBk.Close
Set xlWkBk = Nothing
xlApp.Quit
Set xlApp = Nothing

The error says:
Component Request Pending.  This action cannot be completed because the other application is busy.  Choose 'Switch To' to activate the busy application and correct the problem.
--------------
'Switch To', temporarily removes the error message and show (switches to) vb 6 code window.  Upon clicking on this code window, the error message reappears.  I have to use End Task to end this cycle.
--------
Q1. What component I need to add in reference section to solve this problem?  (I had a previous error on "Dim xlApp As New Excel.Application" and had to check "Microsoft Excel" in component reference section to deal with it.)

Q2. I was expectiong Excel to open after: Set xlWkBk = xlApp.Workbooks.Open("C:\MyFolder\Test.xls")      It maybe opens hidded and that is why 'Swich To' doesn't work?  Not sure about it.  Besides, I wouldn't know what to fix there either.

Do you have some direction for me to take?  I am lost.

Mike
0
Comment
Question by:Mike Eghtebas
1 Comment
 
LVL 22

Accepted Solution

by:
DarkoLord earned 1000 total points
ID: 11754518
Put

xlApp.Visible = True

before xlWkSht.PrintPreview


Darko
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

864 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