Originariamente inviato da soul79
Ciao a tutti,
ho fatto un programma che scrive su un foglio excel delle righe.
Il programma gira senza problemi prima di creare l'eseguibile ma una volta creato l'eseguibile, in fase di caricamento di excel, mi da l' "error run-time '13' type mismatch".
L'errore viene fuori subito dopo che la riga di excel è stata valorizzata.
Come è possibile che prima di creare l'eseguibile non ho problemi e quando lo creo ne ho?
Per favore aiutatemi
Vi riporto di seguito il codice:

Private Sub Command1_Click()
Dim trovato As Integer
Dim num_rig As Integer
Dim path As String
Dim lunghezza As Integer
Dim pippo As Boolean
Dim I As Integer

suser = VBA.Environ("username")


Dim XLS As New Excel.Application
With XLS
.Workbooks.Open (miaVarForm2)
.Worksheets(1).Select
.Visible = True
End With



'UsedRange indica che considera solo il range usato e quindi righe non vuote

num_rig = XLS.Worksheets(1).UsedRange.Rows.Count


num_rig = num_rig + 1


'trovo la prima riga libera
If XLS.Worksheets(1).Range("A" & num_rig).Value = "" Then
I = num_rig
End If


'CODICE PER SETTARE IL BORDO

With XLS.Worksheets(1).Range("A1:F1").Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With



With XLS.Worksheets(2).Range("A1:G1").Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With



'verifico che il record che sto per caricare non ci sia già

num_rig = XLS.Worksheets(1).UsedRange.Rows.Count
trovato = 0
'ricerca del file da scaricare
For I = 1 To num_rig

If (XLS.Worksheets(1).Range("B" & I).Value = Text2.Text) And (XLS.Worksheets(1).Range("C" & I).Value = Text3.Text) Then



Dim Risposta As Long
Risposta = MsgBox(Prompt:="IL RECORD E' GIA' PRESENTE NEL DATABASE. VUOI SOMMARE I DUE RECORDS?", _
Title:="Attenzione", _
Buttons:=vbYesNo + vbQuestion)

If Risposta = vbYes Then

trovato = 1
XLS.Worksheets(1).Range("E" & I).Value = XLS.Worksheets(1).Range("E" & I).Value + Text5.Text




path = ("C:\Documents and Settings\" & suser & "\Documenti\RIPRENDI.XLW")
'PER CANCELLARE UN FILE USO KILL
'invece la funzione FileEsiste1 per verificare se esiste un file
pippo = FileEsiste1(path)
If pippo = "Vero" Then
Kill (path)
End If




XLS.Visible = False
XLS.SaveWorkspace
XLS.Quit

'CARICARE IL FILE NELL'OGGETTO OLE
OLE1.CreateEmbed (miaVarForm2)



Exit For ' For I = 1 To num_rig




Else ' If Risposta = vbYes Then

MsgBox ("INSERIRE DATI MATERIALI CORRETTI")
trovato = 1

End If ' If Risposta = vbYes Then


End If 'If (XLS.Worksheets(1).Range("B" & I).Value = Text2.Text) And (XLS.Worksheets(1).Range("C" & I).Value = Text3.Text) Then

Next 'For I = 1 To num_rig


If trovato = 1 Then
Exit Sub
End If 'If trovato = 1 Then

'scrivo nella prima riga libera


XLS.Worksheets(1).Range("A" & I).Value = Text1.Text
XLS.Worksheets(1).Range("B" & I).Value = Text2.Text
XLS.Worksheets(1).Range("C" & I).Value = Text3.Text
XLS.Worksheets(1).Range("D" & I).Value = Text4.Text
XLS.Worksheets(1).Range("E" & I).Value = Text5.Text
XLS.Worksheets(1).Range("F" & I).Value = Text6.Text


path = ("C:\Documents and Settings\" & suser & "\Documenti\RIPRENDI.XLW")

'PER CANCELLARE UN FILE USO KILL
'invece la funzione FileEsiste1 per verificare se esiste un file
pippo = FileEsiste1(path)
If pippo = "Vero" Then
Kill (path)
End If

'-------------
'
XLS.Visible = False
XLS.SaveWorkspace
XLS.Quit

'CARICARE IL FILE NELL'OGGETTO OLE
OLE1.CreateEmbed (miaVarForm2)


e' strano perchè il file excel lo valorizza ma sembra che va qualcosa male in fase di salvataggio. Pero' dal tipo di errore non si direbbe. E poi solo se compilo il programma?
Per favore sto impazzendo