FINALIZAR PROCESSO

USUARIO.EXCLUIDOS 12/04/2004 15:05:27
#20067
Preciso finalizar o processo do excel, e não estou conseguido. Tenho o seguinte código:

Private Sub vbuButton3_click()
'ROTINA PARA EXPORTAR OS DADOS DAS GRIDÂÂÂ'S PARA ARQUIVO XLS
Dim a As String
Dim b As String
Dim c As String
Dim i As Integer
Dim excl As New Excel.Application
Dim pasta As New Excel.Workbook
Dim d As Integer
Dim div, cont


If grade.Rows = 2 Then
MsgBox ("Não existem dados para serem exportados, ou tabela em branco!"), vbExclamation
data1_pes.SetFocus
Else

Set xl = CreateObject("excel.application")
Set xlw = xl.Workbooks.Add

ProgressBar1.Visible = True
cont = grade.Rows - 1
div = (100 / cont)

With grade
For i = o To .Rows - 1
a = "A"
b = "B"
c = "C"
Range(a & 1).Value = Form4.Caption
Range(a & 1).Font.Bold = True
Range(a & 2).Value = "Agrupado OS"
Range(a & 2).Font.Bold = True
Range(a & 2).Font.Color = &HFF&
Range(a & i + 3).Formula = .TextMatrix(i, .Col - 2)
Range(a & i + 3).ColumnWidth = 12
Range(b & i + 3).Formula = .TextMatrix(i, .Col - 1)
Range(b & i + 3).ColumnWidth = 21
Range(c & i + 3).Formula = .TextMatrix(i, .Col)
Range(c & i + 3).ColumnWidth = 8
If (ProgressBar1.Value + div) 100 Then
ProgressBar1.Value = ProgressBar1 + div
End If
Next i
End With

ProgressBar1.Value = 0
ProgressBar1.Visible = False

With grade1
For i = o To .Rows - 1
a = "F"
b = "G"
Range(a & 2).Value = "Agrupado Diretoria"
Range(a & 2).Font.Bold = True
Range(a & 2).Font.Color = &HFF&
Range(a & 2).Font.Bold = True
Range(a & i + 3).Formula = .TextMatrix(i, .Col - 1)
Range(a & i + 3).ColumnWidth = 21
Range(b & i + 3).Formula = .TextMatrix(i, .Col)
Range(b & i + 3).ColumnWidth = 8
If (ProgressBar1.Value + div) 100 Then
ProgressBar1.Value = ProgressBar1 + div
End If
Next i
End With
MsgBox ("Arquivo ** C:el_agrup_dir.xls ** criado com sucesso."), vbExclamation
ProgressBar1.Value = 0
ProgressBar1.Visible = False
xlw.Close True, "c:el_agrup_dir.xls"

End If
End Sub

Eu consigo fechar a planilha, salvar ela, poré, o processo do excel ainda continua aberto, como faço para fechar o mesmo ?????
USUARIO.EXCLUIDOS 12/04/2004 16:03:32
#20072
Resposta escolhida
Destrua a variavel xl no final procedimento que Excel ira encerrar.

xlw.Close True, "c:el_agrup_dir.xls"
Set xlw = Nothing
Set xl = Nothing
USUARIO.EXCLUIDOS 12/04/2004 17:05:20
#20104

O LUIS tem razão essas variaveis não estão sendo usadas... A variavel "d" tambem pode ser jogada fora !

CEBADIOS,
Poste novamente seu código e aponte em qual linha esta ocorrendo o erro !
Testei a resposta que te passei com VB6, Office e Windows 2000 e não tive problemas !

Talvez vc esteja usando as variáveis xl e xlw em outro ponto do programa após as mesmas terem sido destruidas.
USUARIO.EXCLUIDOS 12/04/2004 17:57:48
#20143
Puxa CEBADIOS fica dificil eu te dizer se vc deveria criar 2 novas variaveis ou talvez mudar um pouco a lógica da sua aplicação... Pois não tenho idéia de como a sua aplicação esta !
Tópico encerrado , respostas não são mais permitidas