Hello everyone!
I have a problem that I hope you'll be able to help me with.
I'm using VB6 to create some reports in Excel. Depending on the type of report, there will be different number of columns.
So, I have
xsl as Excel.Application
wbk as Workbook
wsh as Worksheet
[/color blue]
I initialize variables, do database stuff and then drop data into Excel and call formatting procedure:
wsh.Range("A2").CopyFromRecordset ors
Call Format_XSL(wsh, repType)
[/color blue]
----------------------------------
In Format_XSL procedure:
If LCase(projType) = "native" Then
wsheet.Columns("G:K").Select [/color blue]
'MsgBox "The Selection type is " & TypeName(Selection)[/color green]
Selection.Delete Shift:=xlToLeft
End If
[/color blue]
-------------------------
There are more different statements in that procedure. I just showed one to make it quick.
After formatting is done, I save report and dispose of created objects.
Set wsh = Nothing
wbk.Close
Set wbk = Nothing
xsl.Quit
Set xsl = Nothing
MsgBox "Done"
[/color blue]
Everything works fine if I just run it once and exit the application. But if I try to do it more than once, statement:
Selection.Delete Shift:=xlToLeft
fails with error 91.
Any idea what is not right?
Thank you in advance.
I have a problem that I hope you'll be able to help me with.
I'm using VB6 to create some reports in Excel. Depending on the type of report, there will be different number of columns.
So, I have
xsl as Excel.Application
wbk as Workbook
wsh as Worksheet
[/color blue]
I initialize variables, do database stuff and then drop data into Excel and call formatting procedure:
wsh.Range("A2").CopyFromRecordset ors
Call Format_XSL(wsh, repType)
[/color blue]
----------------------------------
In Format_XSL procedure:
If LCase(projType) = "native" Then
wsheet.Columns("G:K").Select [/color blue]
'MsgBox "The Selection type is " & TypeName(Selection)[/color green]
Selection.Delete Shift:=xlToLeft
End If
[/color blue]
-------------------------
There are more different statements in that procedure. I just showed one to make it quick.
After formatting is done, I save report and dispose of created objects.
Set wsh = Nothing
wbk.Close
Set wbk = Nothing
xsl.Quit
Set xsl = Nothing
MsgBox "Done"
[/color blue]
Everything works fine if I just run it once and exit the application. But if I try to do it more than once, statement:
Selection.Delete Shift:=xlToLeft
fails with error 91.
Any idea what is not right?
Thank you in advance.