VBA

Moderators: PavlinII
Number of threads: 1614
Number of posts: 3000

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
VB 6 -Excel application problem Posted by kel1981b on 17 Oct 2003 at 7:35 AM
First of all this is not VBA code. It's VB 6. Personaly I hate Excel and do not have that much experience coding VB 6 with Excell. But my boss like it. So ... Here it is the problem. For some reason, I cannot open .xls file generated by my application till application running. Let me explain. I run the Application, it generates .xls file. So far so good. Now I want to open .xls file from Explorer without stopping VB application. I minimize application form, open Explorer and double click on .xls file. Something strange happened. File is opened just partially, all other part of screen is still Explorer window. If I stop VB application completely, I can open .xls file from Explorer without any problem. Opening file from Excel don't cause any problem either even if, VB application is not stoped. Seems to me something stuck in the memory. I thing I destroy all Excel objects generated by VB application but looks like I missed something or did something wrong.
Here is piece of my code
 Dim objWorkbook As excel.Workbook
 Dim objExcel As excel.Application
 Dim objSheet As excel.Worksheet
 
 Set objExcel = New excel.Application
 Set objWorkbook = excel.Workbooks.Add
 
 For G = 1 To 2
    objExcel.DisplayAlerts = False
    objWorkbook.Sheets(G).Delete
 Next
 
 With objWorkbook
          
             .Sheets(1).Name = "Monthly"
             
             .Sheets(1).Range("A1:K1").Font.Bold = True
             .Sheets(1).Range("A1:K1").Columns(1).ColumnWidth = 20
             .Sheets(1).Range("A1:K1").Columns(2).ColumnWidth = 60
             .Sheets(1).Range("A1:K1").Columns(3).ColumnWidth = 10
             .Sheets(1).Range("A1:K1").Columns(4).ColumnWidth = 30
 
             .Sheets(1).Cells(1, 1) = "Customer Code"
             .Sheets(1).Cells(1, 2) = "Customer Name"
             .Sheets(1).Cells(1, 3) = "Request ID"
             .Sheets(1).Cells(1, 4) = "Report/Copy Type"
             .Sheets(1).Cells(1, 5) = "Primary Name"
 
         Do Until rsMonthly.EOF
             
             .Sheets(1).Cells(1, 1) = "Customer Code"
             .Sheets(1).Cells(1, 2) = "Customer Name"
             .Sheets(1).Cells(1, 3) = "Request ID"
             .Sheets(1).Cells(1, 4) = "Report/Copy Type"
 
              rsMonthly.MoveNext
         Loop
         'it's jaust part of the code
 
 End With
         
 strFileName = "C:\TestReportMontly.xls"
 
 objWorkbook.SaveAs strFileName
 
 
 objWorkbook.Close
 objExcel.DisplayAlerts = False
 objExcel.Quit
 
 Set objSheet = Nothing
 Set objWorkbook = Nothing
 Set objWorkbooks = Nothing
 Set objExcel = Nothing
 


Hate to say that but need help ASAP

Any help, advises, opinion will be highly appreciated


Report
Re: VB 6 -Excel application problem Posted by PavlinII on 29 Oct 2003 at 12:46 PM
: First of all this is not VBA code. It's VB 6. Personaly I hate Excel and do not have that much experience coding VB 6 with Excell. But my boss like it. So ... Here it is the problem. For some reason, I cannot open .xls file generated by my application till application running. Let me explain. I run the Application, it generates .xls file. So far so good. Now I want to open .xls file from Explorer without stopping VB application. I minimize application form, open Explorer and double click on .xls file. Something strange happened. File is opened just partially, all other part of screen is still Explorer window. If I stop VB application completely, I can open .xls file from Explorer without any problem. Opening file from Excel don't cause any problem either even if, VB application is not stoped. Seems to me something stuck in the memory. I thing I destroy all Excel objects generated by VB application but looks like I missed something or did something wrong.
: Here is piece of my code
:
:  Dim objWorkbook As excel.Workbook
:  Dim objExcel As excel.Application
:  Dim objSheet As excel.Worksheet
:  
:  Set objExcel = New excel.Application
:  Set objWorkbook = excel.Workbooks.Add
:  
:  For G = 1 To 2
:     objExcel.DisplayAlerts = False
:     objWorkbook.Sheets(G).Delete
:  Next
:  
:  With objWorkbook
:           
:              .Sheets(1).Name = "Monthly"
:              
:              .Sheets(1).Range("A1:K1").Font.Bold = True
:              .Sheets(1).Range("A1:K1").Columns(1).ColumnWidth = 20
:              .Sheets(1).Range("A1:K1").Columns(2).ColumnWidth = 60
:              .Sheets(1).Range("A1:K1").Columns(3).ColumnWidth = 10
:              .Sheets(1).Range("A1:K1").Columns(4).ColumnWidth = 30
:  
:              .Sheets(1).Cells(1, 1) = "Customer Code"
:              .Sheets(1).Cells(1, 2) = "Customer Name"
:              .Sheets(1).Cells(1, 3) = "Request ID"
:              .Sheets(1).Cells(1, 4) = "Report/Copy Type"
:              .Sheets(1).Cells(1, 5) = "Primary Name"
:  
:          Do Until rsMonthly.EOF
:              
:              .Sheets(1).Cells(1, 1) = "Customer Code"
:              .Sheets(1).Cells(1, 2) = "Customer Name"
:              .Sheets(1).Cells(1, 3) = "Request ID"
:              .Sheets(1).Cells(1, 4) = "Report/Copy Type"
:  
:               rsMonthly.MoveNext
:          Loop
:          'it's jaust part of the code
:  
:  End With
:          
:  strFileName = "C:\TestReportMontly.xls"
:  
:  objWorkbook.SaveAs strFileName
:  
:  
:  objWorkbook.Close
:  objExcel.DisplayAlerts = False
:  objExcel.Quit
:  
:  Set objSheet = Nothing
:  Set objWorkbook = Nothing
:  Set objWorkbooks = Nothing
:  Set objExcel = Nothing
:  

:
: Hate to say that but need help ASAP
:
: Any help, advises, opinion will be highly appreciated
:
:
:
Hi, I understand that needing help isn't pleasant But even the best sometimes don't know...
I had this problem several weeks ago...
Solution is unexpected and irrational but works
Do not Quit objExcel
  objWorkbook.Close
  objExcel.DisplayAlerts = False
'  objExcel.Quit    - Do not do this
  
  Set objSheet = Nothing
  Set objWorkbook = Nothing
  Set objWorkbooks = Nothing
  Set objExcel = Nothing    'But if you do this, it will work

Hope thiw is enough

PavlinII



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.