Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / February 2004



Tip: Looking for answers? Try searching our database.

oXLApp.Visible = True

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nelsonchang@tristateww.com - 23 Feb 2004 07:31 GMT
Hi,
I have a VB program like below. oXLApp, oXLWBook, oXLWSheet are declared as global variables. The function is called by a button click event. In first time, the excel is displayed after executing "oXLApp.Visible = True". Then I saved the excel & close the excel.
But in second time, the excel never show up. I really don't know why?

==================================
' Global variable
Public oXLApp  As Excel.Application
Public oXLWBook As Excel.Workbook
Public oXLWSheet As Excel.Worksheet

'==================================
Public Function genOPReport(frdate, todate) As Boolean
On Error GoTo ErrorHandler

 Set oXLApp = CreateObject("Excel.Application")
  Set oXLWBook = Workbooks.Add
  'oXLApp.Visible = False
  'set oXLWSheet =
   ' Open recordset to enable changes
    Set rstAP = New ADODB.Recordset
   
   
    strSQL1 = "SELECT distinct ane_op_detail.site, ane_op_detail.customer_code, ane_op_detail.style_num " & _
              " FROM ane_sales_detail, ane_op_detail " & _
              " Where ane_op_detail.site = ane_sales_detail.site "

    rstAP.Open strSQL1, Cnxn, adOpenDynamic, adLockPessimistic, adCmdText

    Cnxn.BeginTrans
    recNo = 0
    Do Until rstAP.EOF
       rowno = rowno + 1
       If recNo = 0 Then
          oXLWBook.Sheets.Add
          Set oXLWSheet = oXLWBook.ActiveSheet
          oXLWSheet.Name = "S" + Str(SheetNo)
       End If
       recNo = recNo + 1
       OK = getOPDetail(rstAP!site, rstAP!customer_code, rstAP!style_num, frdate, todate, recNo)
       rstAP.MoveNext
    Loop
    Application.DisplayAlerts = False
    Worksheets("Sheet1").Delete
    Application.DisplayAlerts = True
   
    oXLApp.Visible = True
    oXLApp.Quit
    ' always remember to tidy up before you leave
    Set oXLWSheet = Nothing
    Set oXLWBook = Nothing
    Set oXLApp = Nothing
   
    rstAP.Close
    Set rstAP = Nothing
end function
Ronald Dodge - 24 Feb 2004 20:36 GMT
I'm not really sure what is causing the issue, but based on what you have
coded, I'm going to take a guess at it.

Could the workbook be saved while the application is invisible?  Maybe that
could cause the issue.  I wouldn't think this would create an issue, but one
doesn't know unless one tests it out.

However, if the purpose of hiding the application is to allow the
application to process the data more efficiently without having the screen
updated as it's going along, there is a property called "ScreenUpdating" on
the application object.  Use it in the following manner:

Application.ScreenUpdating = False
Application.ScreenUpdating = True

PLEASE NOTE, if set this property to "False", IT MUST BE SET BACK TO "True"
before the code is fully done executing and returns the control over to the
user, if it allows for user interaction.  This will allow the code to work
more efficiently cause it's not having to spend time updating the screen (or
monitor).

Signature

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000

> Hi,
>  I have a VB program like below. oXLApp, oXLWBook, oXLWSheet are declared as global variables. The function is called by a button click event. In
first time, the excel is displayed after executing "oXLApp.Visible = True".
Then I saved the excel & close the excel.
> But in second time, the excel never show up. I really don't know why?
>
[quoted text clipped - 48 lines]
>      Set rstAP = Nothing
> end function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.