Reputation: 93
I need help reguarding the following code written in Visual Basic 6.0.
Private Sub cmdExcel_Click()
Dim obj As Object
Set obj = CreateObject("Excel.Application")
On Error Resume Next
MkDir "c:\temp"
On Error GoTo 0
MousePointer = vbHourglass
On Error GoTo err
objGrid.m.ExportToXLS "c:\temp\test.xls"
obj.Workbooks.Open "c:\temp\test.xls"
obj.Visible = True
obj.Interactive = True
On Error GoTo 0
err:
MousePointer = vbNormal
End Sub
The enviroment: Windows 10, Office Excel 2016.
The problem: the workbook doesn't show up, but I can still find an Excel instance in Task Manager. If I shut down the instance I can find the Excel in c:\temp
and the application starts working again.
The goal: show the Excel just created.
Do you have any solutions?
Thanks in advance.
Sara
Upvotes: 1
Views: 613
Reputation: 93
I found the solution.
The problem wasn't in the code but in some Excel's settings.
First, I modified the code in order to get a more detailed error. Basically I switched the two instructions which allow Excel App to be visibile and the file to be opened:
obj.Visible = True
obj.Workbooks.Open "c:\temp\test.xls"
In this way, I was able to open Excel App and read the reason why the file could not be opened.
As you can see the file type is Excel 4 Worksheets
which is blocked on opening.
I had to go Trust Center
and disable it.
Just to be sure, I disabled also Excel 4 Workbook
.
After performing the steps above, my app worked.
Upvotes: 1