cs_pong77186
Messages postés3Date d'inscriptionmardi 4 avril 2006StatutMembreDernière intervention 4 mai 2006
-
3 mai 2006 à 17:47
cs_pong77186
Messages postés3Date d'inscriptionmardi 4 avril 2006StatutMembreDernière intervention 4 mai 2006
-
4 mai 2006 à 11:21
Bonjour tout le monde
J'ai un souci VB6 avec EXCEL qui est assez irritant.
Voila dans un 1er bouton ,j'ouvre un fichier excel dans lequel je sélectionne toutes les lignes non vides.
Et dans un 2ème bouton, je reitère la même chose mais avec un fichier différent.
Voila le code :
Option explicit
Dim appExcel As Excel.Application
================================
Private Sub Command1_Click()
'Déclaration des variables
Dim wbExcel As Excel.Workbook
Dim wsExcel As Excel.Worksheet 'Feuille Excel
'Ouverture de l'application
Set appExcel = CreateObject("Excel.Application")
Set wbExcel = appExcel.Workbooks.Open(App.Path & "\Listing.xls")
Set wsExcel = appExcel.ActiveWorkbook.Worksheets("Feuil1")
.Rows("4:4").Select
.Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
appExcel.Application.Workbooks("Listing.xls").Save
End With
Set appExcel = Nothing
Set wsExcel = Nothing
End Sub
=======================================
Private Sub Command2_Click()
Dim wbExcel As Excel.Workbook
Dim wsExcel As Excel.Worksheet 'Feuille Excel
'Ouverture de l'application
Set appExcel = CreateObject("Excel.Application")
Set wbExcel = appExcel.Workbooks.Open(App.Path & "\Listing_save.xls")
Set wsExcel = appExcel.ActiveWorkbook.Worksheets("Détail")
.Rows("4:4").Select
.Range(Selection, ActiveCell.SpecialCells(xlCellTypeLastCell)).Select
appExcel.Application.Workbooks("Listing_save.xls").Save
End With
Set appExcel = Nothing
Set wsExcel = Nothing
End Sub
=======================================
Mon problème est que la sélection pour un 1er fichier fonctionne parfaitement quand je lance command 1, mais lorsque je lance Command 2 j'ai une erreur "une erreur de type variable objet ou variable bloc with non définie" sur la ligne .Range(Selection, ActiveCell.SpecialCells(xlCellTypeLastCell)).Select.
et lorsque je lance command 2 en 1er, c'est sur command 1 que l'erreur se manifeste.
Alors si quelqu'un pouvait m'aider, cela m'aiderait bien
Merci d'avance
valtrase
Messages postés937Date d'inscriptionlundi 19 janvier 2004StatutMembreDernière intervention 9 mai 20223 3 mai 2006 à 19:29
Salut,
Tu devrais tester en utilisant GetObject en lieu et place de CreateObject en faisant ceci tu testes si excel et déjà ouvert donc cela donnerais un truc dans le genre
On Error Resume Next 'Utilisé pour vérifier si Excel s'éxécute
Set appExcel = GetObject(, "Excel.Application") 'Vérifie si Excel est ouvert
If Err.Number <> 0 Then
blRunning = False 'Excel n'était pas en éxecution
Set appExcel = CreateObject("Excel.Application")
Else
blRunning = True
End If
Err.Clear
' ****************************************
ICI TON CODE
' ****************************************
'Si Excel était ouvert on ne le ferme pas
If Not (blRunning) Then
appExcel.Quit
Set appExcel = Nothing
End If
'On libère la mémoire
'Set appExcel = Nothing
Set wbExcelModel = Nothing
Set wbExcelTemp = Nothing
Tu peu toujours aller voir ma source pour plus d'info
cs_pong77186
Messages postés3Date d'inscriptionmardi 4 avril 2006StatutMembreDernière intervention 4 mai 2006 3 mai 2006 à 19:03
Ca n'apparait pas dans le code, mais j'ai déjà essayé de fermé les applications EXCEL, avec wbExcel.close , et appExcel.application.quit, et j'ai toujours le même souci