Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Mise en forme Macro vba

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

tijocanard

XLDnaute Nouveau
Bonour.

Alors mon problème est une question de mise en forme d'un résultat d'une macro.

Je m'explique: J'ai créé sous excel une macro qui se connecte à une base oracle et qui renvois le résultat sur ma feuille excel.

Ma macro:

Code:
Private Sub CommandButton1_Click()
With ActiveSheet.QueryTables.Add(Connection:= _
        "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=id;PWD=pwd;SERVER=server;", _
        Destination:=Range("A1"))
        .CommandText = Array( _
        "SELECT Sum(histo_event_tr.QTE_PROD)as quantite, sysdate" & Chr(13) & "" & Chr(10) & "FROM DEPT_85.histo_event_tr histo_event_tr, DEPT_85.histo_tr histo_tr" & Chr(13) & "" & Chr(10) & "WHERE histo_event_tr.ID_HISTO = histo_tr.ID_HISTO AND ((histo_event_tr.ID_RESS_HIST" _
        , _
        "O='UPAV3_CU11_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU12_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to" _
        , _
        "_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU21_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')) OR (histo_even" _
        , _
        "t_tr.ID_RESS_HISTO='UPAV3_CU22_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')))" _
        )
        .Name = "Lancer la requête à partir de oracle"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertEntireRows
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 15
        .PreserveColumnInfo = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

Donc ma macro me renvoie bien une quantité à une heure donnée. 🙂
Le problème arrive: ma macro se rafraichit toutes les 15min et le nouveau résultat se met en cellulle A1
Normal car j'ai mis:
Code:
Destination:=Range("A1"))

comment faire pour afficher les nouveau résultat en dessous du premier résultat? 😱

J'espere que c'est clair!

L'autre problème est que à chaque rafraichissement, il me remet les entêtes des colonnes (quantité et sysdate), je ne voudrais que le résultat.

De sorte que j'obtienne un tableau pour générer plus tard un graphique.

J'ai bien essayé de bidoullier dans ces options mais j'y arrive pas.

Code:
.FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertEntireRows
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 15
        .PreserveColumnInfo = False
        .Refresh BackgroundQuery:=False

Je débute en vba et votre aide sera précieuse.🙄
 

Pièces jointes

Dernière édition:
Re : Mise en forme Macro vba

Re,

à ma connaissance il n'y a aucun moyen de demander aux données externes de se mettre à jour dans des lignes différentes avec .RefreshPeriod

Donc il va falloir lancer cette même macro toutes les 15 minutes
ça peut être réalisé avec Application.Ontime


Code:
[FONT=monospace][COLOR=#0000fc]Private[/COLOR] [COLOR=#0000fc]Sub[/COLOR] CommandButton1_Click()[/FONT]
[FONT=monospace][COLOR=#0000fc]Dim[/COLOR] Ligne [COLOR=#0000fc]as[/COLOR] [COLOR=#0000fc]Long[/COLOR][/FONT]
[FONT=monospace]Ligne = Range([COLOR=#800000]"A65536"[/COLOR]).[COLOR=#0000fc]end[/COLOR](XluP).row+1[/FONT]
[FONT=monospace][COLOR=#0000fc]With[/COLOR] ActiveSheet.QueryTables.Add(Connection:= _[/FONT]
[FONT=monospace][COLOR=#800000]"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=id;PWD=pwd;SERVER=server;"[/COLOR], _[/FONT]
[FONT=monospace]Destination:=Range([COLOR=#800000]"A"[/COLOR] & Ligne))[/FONT]
[FONT=monospace].CommandText = Array( _[/FONT]
[FONT=monospace][COLOR=#800000]"SELECT Sum(histo_event_tr.QTE_PROD)as quantite, sysdate"[/COLOR] & Chr(13) & [COLOR=#800000]""[/COLOR] & Chr(10) & [COLOR=#800000]"FROM DEPT_85.histo_event_tr histo_event_tr, DEPT_85.histo_tr histo_tr"[/COLOR] & Chr(13) & [COLOR=#800000]""[/COLOR] & Chr(10) & [COLOR=#800000]"WHERE histo_event_tr.ID_HISTO = histo_tr.ID_HISTO AND ((histo_event_tr.ID_RESS_HIST"[/COLOR] _[/FONT]
[FONT=monospace], _[/FONT]
[FONT=monospace][COLOR=#800000]"O='UPAV3_CU11_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU12_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to"[/COLOR] _[/FONT]
[FONT=monospace], _[/FONT]
[FONT=monospace][COLOR=#800000]"_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU21_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')) OR (histo_even"[/COLOR] _[/FONT]
[FONT=monospace], _[/FONT]
[FONT=monospace][COLOR=#800000]"t_tr.ID_RESS_HISTO='UPAV3_CU22_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhhmi')))"[/COLOR] _[/FONT]
[FONT=monospace])[/FONT]
[FONT=monospace].Name = [COLOR=#800000]"Lancer la requête à partir de oracle"[/COLOR][/FONT]
[FONT=monospace].FieldNames = [COLOR=#0000fc](Ligne = 2)[/COLOR][/FONT]
[FONT=monospace].RowNumbers = [COLOR=#0000fc]False[/COLOR][/FONT]
[FONT=monospace].FillAdjacentFormulas = [COLOR=#0000fc]False[/COLOR][/FONT]
[FONT=monospace].PreserveFormatting = [COLOR=#0000fc]True[/COLOR][/FONT]
[FONT=monospace].RefreshOnFileOpen = [COLOR=#0000fc]False[/COLOR][/FONT]
[FONT=monospace].BackgroundQuery = [COLOR=#0000fc]True[/COLOR][/FONT]
[FONT=monospace].RefreshStyle = xlInsertEntireRows[/FONT]
[FONT=monospace].SavePassword = [COLOR=#0000fc]False[/COLOR][/FONT]
[FONT=monospace].SaveData = [COLOR=#0000fc]True[/COLOR][/FONT]
[FONT=monospace].AdjustColumnWidth = [COLOR=#0000fc]True[/COLOR][/FONT]
[FONT=monospace].RefreshPeriod = 0[/FONT]
[FONT=monospace].PreserveColumnInfo = [COLOR=#0000fc]False[/COLOR][/FONT]
[FONT=monospace].Refresh BackgroundQuery:=[COLOR=#0000fc]False[/COLOR][/FONT]
[FONT=monospace].Delete[/FONT]
[FONT=monospace][COLOR=#0000fc]End[/COLOR] [COLOR=#0000fc]With[/COLOR][/FONT]
[FONT=monospace][COLOR=#0000fc]Application.Ontime Now + timevalue("00:15:00"), "[COLOR=#000000]CommandButton1_Click[/COLOR]"[/COLOR][/FONT]
[FONT=monospace][COLOR=#0000fc]End[/COLOR] [COLOR=#0000fc]Sub[/COLOR][/FONT]
 
Dernière édition:
Re : Mise en forme Macro vba

Re,

si la macro "CommandButton1_Click" est dans la Feuil1 de ton classeur (CodeName, pas le nom de la feuille dans Excel), essaye de mettre

Code:
Application.Ontime Now + timevalue("00:15:00"), "Feuil1.CommandButton1_Click"
 
Re : Mise en forme Macro vba

ha mince j'avais édité mon post et tu rep après!

j'ai copié mon code dans un module tout en le laissant dans feuil1 (bidouille quoi)!

mais j'essaye ta soluce...

Edit: c'est tout bon aussi pour cette solution!

Thanks a lot
Et bon week end
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Power Query power query
Réponses
22
Affichages
4 K
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…