简体   繁体   中英

VB6 extracts in Excel 2013

I have a few applications writting in legacy VB6 that have extract code built into to create EXCEL extracts. We are moving from Excel 2007 to Excel 2013 and I've run into some issues. I'm running Windows 10. In 2007, this is my declarations and Set statements that used to work just fine...

Option Explicit
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheetA As Excel.Worksheet

These I have at the top of the module.

In my Function that writes the data to extract I do this...

Set xlApp = New Excel.Application
Set xlBook = XlApp.Workbooks.Add
Set xlSheetA = xlBook.Worksheets.Add

When it gets to XLBook - it hangs up and everything stops working. I get an error:

This action cannot be completed because the other program is busy. Choose "SwitchTo' to activate the busy program and correct the problem.

Now, before I run my extract I make sure Excel is not running in the background, to check I go to Task Manager -> processes and delete it if it's there. What am I doing wrong? how should I change my code?

EDIT SCREENSHOTS: The screensnhots do not display the code that i have in my application. this was a new project just to show all the code I'm using. 码 错误

Your function1 is in a private sub, should be called as a function. Your code shown and the screenshots also differ. I have created a quick sample and it works perfect in Excel 2013. Changed the sub to function...

Option Explicit

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheetA As Excel.Worksheet

Private Function function1()

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheetA = xlBook.Worksheets.Add

Set xlSheetA = xlBook.Sheets.Item(1) ''the sheet you want to use

xlApp.Visible = True

xlApp.ActiveSheet.Cells(1, 1).Value = "TEST"

xlApp.Workbooks.Close

MsgBox "Excel Done"
End Function

Private Sub Command3_Click()

Call function1
End Sub

Hope this helps.

Edit: See screenshot below, working fine...

打开Excel

Long back I had similar issue. Not sure if this relates to your scenario. My code was updating an opened excel which had a cell in edit mode. After trying many possibilities, I turned off screen updating and visibility until code finished. Something like xlApp.ScreenUpdating = False xlApp.Visible = False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM