Hey!
The code supposed to insert both toptext, bottomtest and some
maintext/bodytext on page 1 of the document. If the user writes enought
text so that it gets to page 2, 3 ..then ONLY some of the fields in the
toptext is supposed to be inserted.
1) On page 1 it is supposed to update toptext, main body and footers.
2) The page break is used here just make the insertion of the toptext
on page 2 (i think)
3) On page 2, only the toptext is with the same fields as page 1 is
supposed to be here.
I'll paste the code for the whole macro below, and the "symfoni.ini"
file below the macro. Maybe you'll see the error or can help to make it
work in all versions (97/2000/2003)?
Declare Function GetWindowsDirectory Lib "kernel32" Alias
"GetWindowsDirectoryA" (ByVal Dill As String, ByVal Dall As Long) As
Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString
As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpString As String, ByVal lpFileName As
String) As Long
Private Declare Function CharToOem Lib "user32" Alias "CharToOemA"
(ByVal LpszSrc As String, ByVal lpszDst As String) As Long
Private Declare Function OemToChar Lib "user32" Alias "OemToCharA"
(ByVal LpszSrc As String, ByVal lpszDst As String) As Long
Sub AutoOpen()
'
' AutoOpen Makro
' Makro for innhenting av verdier fra ©Cinet Symfoni
'
Dim WinSTR ' Størrelse på returstreng
Dim WinDIR$ ' Streng for Win-katalog
Dim check
Dim Data$
Dim totalData$
Dim SymfoniDat$
Dim Keyword$
Dim KopiTil$ 'For KopiTil-data som kan bli for stort for
docproperty-felt
Dim SendTil$ 'Ta 2.12.98
Dim Show$ 'Getronics Sogn og Fj. 23.2.2000-IMB, BRM Show
JA/NEI i Symfoni.ini
'Variabel brukt til å sjekke status i
Symfoni.ini for
'Show = Ja/Nei for å kunne opne Worddok. på
web utan å hente inn
'verdiar på nytt frå Symfoni.ini og utan å
få spm. om lagring.
'Set Show = JA i WebQueryOpen i skjema for
webdok. => Viser dok.
'utan å hente inn verdiar og utan å be om
lagring v. lukking av
'Worddok.
On Error GoTo Avslutt
Show$ = "Ja" 'Getronics Sogn og Fj. 23.2.2000-IMB, BRM Show JA/NEI i
Symfoni.ini
WinSTR = 144
WinDIR$ = String(144, 32)
ActiveDocument.CustomDocumentProperties("SHOW") = "Ja" 'Getronics -
BRM,Show JA/NEI i Symfoni.ini
check = GetWindowsDirectory(WinDIR$, WinSTR)
'WordBasic.ChDir WinDIR$
'Initialiser variabel for filen Symfoni.INI
'SymfoniDat$ = "symfoni.ini"
tDir$ = Trim(WinDIR$)
tmp$ = Left(tDir$, Len(tDir$) - 1)
SymfoniDat$ = tmp$ & "\" & "symfoni.ini"
'Åpner filen Symfoni.INI
Open SymfoniDat$ For Input As #1
'Sjekker dokumentstatus: Står alltid i 2.linje [SHOW] - Ja/Nei
Line Input #1, Data$
Line Input #1, Data$
Data$ = LTrim$(RTrim$(Data$))
Show$ = LTrim$(RTrim$(Data$)) 'Getronics Sogn og Fj. 23.2.2000-IMB,
ActiveDocument.CustomDocumentProperties("SHOW") = Data$ 'BRM Show
JA/NEI i Symfoni.ini
If Data$ <> "Nei" Then
GoTo Avslutt
End If
'Sjekk om data er innlest tidligere, dersom dette er tilfelle
'spør om det skal leses inn på nytt.
'If ActiveDocument.CustomDocumentProperties("Innlest") = "Ja" Then
' If MsgBox("Skal data leses inn fra Symfoni?", vbYesNo + vbCritical +
vbDefaultButton2, "Lese inn data?") = vbNo Then
' GoTo Avslutt
' End If
'End If
'Les inn data fra Symfoni.INI
On Error GoTo ErrorHandling ' Hvis feltet ikke finnes, returneres en
feil ved innlesing av Data$. Feltet skal droppes !
Line Input #1, Data$
Data$ = LTrim$(RTrim$(Data$))
While Not EOF(1)
teller% = 0
If Left$(Data$, 1) = "[" Then
Keyword$ = Mid$(Data$, 2, Len(Data$) - 2)
Line Input #1, Data$
Data$ = LTrim$(RTrim$(Data$))
While Left$(Data$, 1) <> "[" And Not EOF(1)
If teller% > 0 Then
totalData$ = totalData$ & "," & Chr(10) &
LTrim$(RTrim$(Data$))
Else
totalData$ = Data$
End If
Line Input #1, Data$
teller% = teller% + 1
Wend
If Keyword$ = "SENDTO" Then SendTil$ = totalData$
If Keyword$ = "COPYTO" Then KopiTil$ = totalData$
ActiveDocument.CustomDocumentProperties(Keyword$) = totalData$
totalData$ = ""
End If
Wend
'Oppdaterer alle felter hentet fra Symfoni.INI - også header/footer -
og går til start av dokumentet
'sjekk om bokmerke eksisterer
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'endring Cinet Sogn start
Selection.InsertBreak Type:=wdPageBreak
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Or
ActiveWindow.ActivePane.View.Type _
= wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.TypeBackspace
'stopp endring
Selection.HomeKey unit:=wdStory
If ActiveDocument.Bookmarks.Exists("SendTil") Then
WordBasic.EditGoto Destination:="SendTil"
Selection.StartOf unit:=wdWord, Extend:=wdMove
Selection.EndOf unit:=wdCell, Extend:=wdExtend
Selection.Delete
WordBasic.Insert SendTil$
SendTil$ = ""
End If
If ActiveDocument.Bookmarks.Exists("KopiTil") Then
WordBasic.EditGoto Destination:="KopiTil"
Selection.StartOf unit:=wdWord, Extend:=wdMove
Selection.EndOf unit:=wdCell, Extend:=wdExtend
Selection.Delete
WordBasic.Insert KopiTil$
KopiTil$ = ""
End If
If ActiveDocument.Bookmarks.Exists("Overskrift") Then
WordBasic.EditGoto Destination:="Overskrift"
Selection.StartOf unit:=wdParagraph, Extend:=wdMove
Selection.MoveEnd unit:=wdParagraph, Count:=1
Temp$ = ActiveDocument.CustomDocumentProperties("Subject")
WordBasic.Insert Temp$
End If
If ActiveDocument.Bookmarks.Exists("Start") Then
WordBasic.EditGoto Destination:="Start"
Else
Selection.MoveDown unit:=wdLine, Count:=1
End If
'Endrer status på dokumentet
ActiveDocument.CustomDocumentProperties("Innlest") = "Ja"
ErrorHandling:
Resume Next
Avslutt:
Close #1
End Sub
Sub AutoClose()
If (ActiveDocument.CustomDocumentProperties("Innlest") = "Ja" And
(ActiveDocument.FullName <>
ActiveDocument.CustomDocumentProperties("SymfoniFileName"))) Then
On Error Resume Next
ActiveDocument.Close _
SaveChanges:=wdDoNotSaveChanges, _
OriginalFormat:=wdOriginalDocumentFormat
Exit Sub
End If
On Error Resume Next
If ActiveDocument.CustomDocumentProperties("SHOW") = "Ja" Then
ActiveDocument.Saved = True
Else
lagre = MsgBox("Ønsker du å lagre dokumentet?", vbYesNo, "Lagre")
If lagre = vbYes Then
ActiveDocument.Save
Else
ActiveDocument.Saved = True
End If
End If
Application.WindowState = wdWindowStateMinimize
End Sub
***THE INI FILE****
[SHOW]
Nei
[SymfoniFileName]
C:\DOCUME~1\fosvesto.FOR\LOKALE~1\Temp\SE6LKFEK.doc
[FROM-USERNAME]
Svein Erik Storkås
[FROM-COMPANY]
Førde kommune
[FROM-ETAT]
IKT
[FROM-COMPANYADDRESS]
Pb. 338
[FROM-ZIPCODE]
6802
[FROM-CITY]
FØRDE
[FROM-COMPANYADDRESS2]
Hafstadvegen 21
[FROM-COUNTRY]
Norge
[FROM-EMAIL]
(e-mail address removed)
[FROM-PHONE]
57 72 20 00
[FROM-FAX]
57 72 20 10
[FROM-BANKACCOUNT]
3700 07 00720
[FROM-WEB]
www.forde.kommune.no
[UNNTATT OFFENTLIGHET]
Brev
[FROM-USERS-KVSJEF]
Åge Klausen
[POSTGIRO]
[FROM-ENTERPRISENO]
NO 963923511 mva
[FROM-USERS-TITLE]
Konsulent
[FROM-USERS-PHONE]
57722005
[ICOPYTO]
[FROM-USERS-MANAGER]
Åge Klausen
[FROM-USERS-MANAGERTITLE]
Leiar
[FROM-USERS-INITIALS]
SES
[FROM-USERS-FUNCTION]
[FROM-USERS-MAILADDRESS]
Svein Erik Storkås/Forde Kommune
[FROM-USERS-FAXNO]
57722010
[FROM-UNIT-CODE]
it
[FROM-UNIT]
IKT
[FROM-DEP-CODE]
FK
[FROM-DEPARTMENT]
Førde kommune
[FROM-DIVISION]
Førde Kommune
[TO-COMPANYNAME]
Svein P. Erdal
[TO-COMPANYADDRESS]
Bregnetunet 7
[TO-ZIPCODE]
6800 FØRDE
[TO-CONTACT]
[TO-COUNTRY]
[YOURREF]
[YOURDATE]
[OURDATE]
31.01.2006
[SUBJECT]
Test
[COPYTO]
[OURREF]
1998/000001
[PART-ARCHIVE]
fs
[ARCHIVE-CODE]
OP 43/245
[UNNTATT-OFFENTLIGHET]
[ANTALL-VEDLEGG]
[THEEND]
Thank you very much for your help, i really appreciate it!