PDA

View Full Version : PrivateProfileString error



DJLogiciel
07-02-2016, 01:36 AM
I use in a macro word this code to generate and read personnal parameters in a .ini file
This macro was working correctly under Windos XP Pro and WORD 2010
Now under Windows 10 Pro and WORD 2016 i have problems !
Can you help me ? Thanks

Public Sub Lettre()
' Main Macro
' Macro créée le 22/08/00 par Jean-Jacqes DULUC
'


Selection.GoTo What:=wdGoToBookmark, Name:="Date"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.InsertDateTime DateTimeFormat:="d MMMM yyyy", InsertAsField:= _
False, DateLanguage:=wdFrench, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'
' ---- Procedure d'insertion d'un chrono à un doc sans chrono ----


Dim Utilisateur As Integer
Dim Initiales As String
Dim TypDoc As String
Dim Prefixe As String
Dim Reference As String
Dim CheminDoc As String
Dim FichierChrono As String
Dim FichierINI As String
Dim FichierJnl As String
Dim NbCar As Integer
'System.ProfileString("Courrier", "Fichier") = "D:\Mes Documents\Word\Chrono.INI"
' ---- Recupère données utilisateur en cours ----
'Récupère dans le modèle la classe du document
Selection.GoTo What:=wdGoToBookmark, Name:="TypeDoc"
TypDoc = Selection.Text
P = InStr(1, TypDoc, "/")
If P > 0 Then
Classe = Trim$(Left$(TypDoc, P - 1))
TypDoc = Right$(TypDoc, Len(TypDoc) - P)
End If
If Trim$(Classe) <> "" Then
Classe = Trim$(Classe)
Else
Classe = "PERSO"
End If


On Error GoTo Correction
FichierChrono = System.ProfileString(Classe + "_" + "CourrierAuto", "FichierChrono")
CheminDoc = System.ProfileString(Classe + "_" + "CourrierAuto", "CheminDoc")
FicJnl = System.ProfileString(Classe + "_" + "CourrierAuto", "FicJnl")
Prefixe = System.ProfileString(Classe + "_" + "CourrierAuto", "Prefixe")
NbCar = Val(System.ProfileString(Classe + "_" + "CourrierAuto", "NbCar"))
GoTo Suite
Correction:
Load DefAuto
DefAuto.NbCar.Value = NbCar
DefAuto.FicChrono.Value = FichierChrono
DefAuto.RepDoc.Value = CheminDoc
DefAuto.FicJnl.Value = FicJnl
DefAuto.Show
Suite:
On Error GoTo 0
If ActiveDocument.Bookmarks.Exists("Nom") Or ActiveDocument.Bookmarks.Exists("Objet") Or ActiveDocument.Bookmarks.Exists("Référence") Then
' ---- Détecte si le document est compatible ----
ActiveDocument.Bookmarks("Référence").Select
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If FichierChrono <> "" Then
' ---- Détecte si le document est déjà référencé ----
' ---- Création du chrono ----
Dim ValChrono As String
Dim ChronoComplet As String
Dim Sfic As String
Dim Année As String
Dim NumChrono As String
Année = "20" + Right$(Date, 2)
Sfic = CompleteRep(CheminDoc) & FichierChrono
'On Error Resume Next
'Here Sfic value = ":\Documents\Word\Chroni.ini"
' This file exist
NumChrono = System.PrivateProfileString(Sfic, "Courrier", Année)
' See file attached for error message
If NumChrono = "" Then
System.PrivateProfileString(CompleteRep(CheminDoc) & FichierChrono, "Courrier", Année) = 0
End If
ChronoComplet = Trim$(Val(NumChrono) + 1)
While Len(ChronoComplet) < NbCar
ChronoComplet = "0" & ChronoComplet
Wend
ChronoComplet = Année & "." & ChronoComplet
Prefixe = Trim$(Prefixe)
If Right$(Prefixe, 1) = "/" Then Prefixe = Left$(Prefixe, Len(Prefixe) - 1)


If Trim$(Prefixe) <> "" Then ChronoComplet = Prefixe + "/" + ChronoComplet
' ---- Insertion du chrono dans le document ----
' Reference = Left(Reference, InStr(Reference, "***") - 1)
'Reference = Reference + ValChrono + Fin

Selection.GoTo What:=wdGoToBookmark, Name:="Référence"
'ActiveDocument.Bookmarks("Référence").Select
Selection.Text = ChronoComplet


Selection.GoTo What:=wdGoToBookmark, Name:="Nom"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
ChDir CheminDoc
Else
MsgBox "Ce document ne peut être référencé." + Chr(10) + Chr(13) + "Il possède déjà une référence.", vbExclamation, "Erreur référence"
End If
Call Affiche_Page
Else
MsgBox "Ce document ne peut être référencé." + Chr(10) + Chr(13) + "Il n'a pas d'auteur, d'objet ou de champs pour le référencement", vbExclamation, "Erreur document"
End If




End Sub



Contents of Chrono.ini
[Courrier]
2002=055
2003=095
2004=065
2005=105
2006=061
2007=048
2008=061
2009=034
2010=031
2011=055
2012=018
2013=015
2014=022
2015=026
2016=036