IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Fichier corrompu aprés copie


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut Fichier corrompu aprés copie
    Bonjour, je rencontre actuellement un problème, je veux copier un fichier local vers sharepoint et je m'y prend de la façon suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    Sub par()
    Dim stfil As String
    Dim t2, t3, t4 As String
    Dim p As Long
    stfil = Application.GetOpenFilename
    If stfil <> "Faux" Then
        If MsgBox("êtes vous sûr de vouloir joindre ce fichier : " & stfil, vbYesNo, "vérification") = vbYes Then
     
            Dim xmlhttp
            Dim sharepointUrl
            Dim FileName
            Dim tsIn
            Dim sBody
            FileName = stfil
            Dim ofc
            Dim ofile
            Set ofc = CreateObject("Scripting.FileSystemObject")
            Set ofile = ofc.GetFile(FileName)
            Set tsIn = ofile.OpenAsTextStream
            sBody = tsIn.ReadAll
            While Not tsIn.AtEndOfStream
            MsgBox tsIn.ReadLine
            Wend
            MsgBox Len(sBody)
            tsIn.Close
            sharepointUrl = "https://sharepoint.com/ect..."
            Dim sharepointFileName
            t2 = Left(ofile.Name, InStr(1, ofile.Name, ".") - 1)
            t3 = StrReverse(Left(StrReverse(ofile.Name), InStr(1, StrReverse(ofile.Name), ".")))
            t4 = Format(Date, "yyyymmdd") & "_" & Format(Time, "hhmmss")
            sharepointFileName = sharepointUrl & "/" & t2 & t4 & t3
            Set xmlhttp = CreateObject("MSXML2.XMLHTTP.4.0")
            xmlhttp.Open "PUT", sharepointFileName, False
            xmlhttp.Send sBody
        End If
    End If
    End Sub

    Mais le problème une fois le fichier sur sharepoint, il est corrompu.

    par exemple pour un fichier PDF, j'ouvre le fichier original (en local) sur un bloc note, puis celui sur sharepoint dans un autre bloc note, je vois qu'il y a un gros vide sur le fichier de sharepoint, il manque plein de caractère sur le fichier de sharepoint.

    J'ai donc pensé que mon textstream ne prend pas tout les caractère

    Si quelqu'un pense a voir une solution a mon problème je suis preneur

    Merci de retour.

  2. #2
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Bonjour je viens de trouvé une solution

    ça peux toujours aidé ^^

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    Sub par()
    Dim stfil As String
    Dim t1, t2, t3, t4 As String
    stfil = Application.GetOpenFilename
    If stfil <> "Faux" Then
        If MsgBox("êtes vous sûr de vouloir joindre ce fichier : " & stfil, vbYesNo, "vérification") = vbYes Then
     
            Dim xmlhttp
            Dim sharepointUrl
            Dim FileName
            Dim tsIn
            Dim sBody
            FileName = stfil
            Dim ofc
            Dim ofile
            Dim objStream, strData
            Dim arr() As String
            Set objStream = CreateObject("ADODB.Stream")
            objStream.Charset = "utf-8"
            objStream.Open
            objStream.Type = 1
            objStream.LoadFromFile (FileName)
            sBody = objStream.Read()
     
            objStream.Close
            Set objStream = Nothing
     
            sharepointUrl = "https://sharepoint.com/ect..."
            Dim sharepointFileName
            arr() = Split(FileName, "\")
            t1 = arr(UBound(arr))
            t2 = Left(t1, InStr(1, t1, ".") - 1)
            t3 = StrReverse(Left(StrReverse(t1), InStr(1, StrReverse(t1), ".")))
            t4 = Format(Date, "yyyymmdd") & "_" & Format(Time, "hhmmss")
            sharepointFileName = sharepointUrl & "/" & t2 & t4 & t3
            Set xmlhttp = CreateObject("MSXML2.XMLHTTP.4.0")
            xmlhttp.Open "PUT", sharepointFileName, False
            xmlhttp.Send sBody
            Feuil1.Hyperlinks.Add anchor:=Range("L24"), Address:=sharepointFileName
        End If
    End If
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. fichier illisible après copie
    Par Bernabé01 dans le forum Débuter
    Réponses: 13
    Dernier message: 29/01/2013, 21h55
  2. [AC-2003] fichier corrompu après plantage
    Par meud007 dans le forum Access
    Réponses: 5
    Dernier message: 31/10/2011, 13h43
  3. Fichier corrompu après copie
    Par Patricia_ dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 11/08/2009, 11h16
  4. Fichier excel corrompu apres copie
    Par jaudurier dans le forum Maven
    Réponses: 6
    Dernier message: 03/07/2007, 10h57
  5. Fichier corrompu après téléchargement HTTP
    Par PP(Team) dans le forum C++
    Réponses: 2
    Dernier message: 26/04/2007, 09h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo