Selvfølgelig her er den :
*******************UserForm1***********
Dim Data As Module1.ArkivData
Private Sub lblAdresse_Click()
End Sub
Private Sub CommandButton3_Click()
End Sub
Private Sub CommandButton4_Click()
End Sub
Private Sub Afdeling_Change()
End Sub
Private Sub CommandButton5_Click()
'Åbner filen store 2
ChangeFileOpenDirectory _
CurDir
Documents.Open FileName:="store3.doc", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=True, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
'Kopier data
Dim LblNr As Variant
LblNr = Array(lblWrite1.Value, lblWrite2.Value, lblWrite3.Value, lblWrite4.Value)
For t = 0 To 3
If LblNr(t) = True Then
'Slet række
Selection.GoTo What:=wdGoToBookmark, Name:="Lbl" & t + 1
Selection.SelectRow
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
'Indskriv Data
Selection.GoTo What:=wdGoToBookmark, Name:="Lbl" & t + 1
Selection.TypeText Text:="Internt nummer: " & lblinterntnr.Text
Selection.TypeParagraph
Selection.TypeText Text:="Beskrivelse: " & lblBeskrivelse.Text
Selection.TypeParagraph
Selection.TypeText Text:="Datoperiode: " & lblDatoperiode.Text
Selection.TypeParagraph
Selection.TypeText Text:="Indhold: " & lblIndhold.Text
Selection.TypeParagraph
Selection.TypeText Text:="Kasse nr.: " & lblKassenr.Text
'Indskriv Afdeling(434)
Selection.GoTo What:=wdGoToBookmark, Name:="LblA" & t + 1
Selection.TypeText Text:="434"
'Indskriv Kassationssår
Selection.GoTo What:=wdGoToBookmark, Name:="LblK" & t + 1
Selection.TypeText Text:=lblKassation.Text
End If
Next t
ActiveDocument.SaveAs FileName:="store3.doc", FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
Windows("store3.doc").Close
Windows("Arkiv1.doc").Activate
End Sub
Private Sub CommandButton6_Click()
'Åbner filen store 2
Documents.Open FileName:="store3.doc", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=True, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
For t = 0 To 3
Selection.GoTo What:=wdGoToBookmark, Name:="Lbl" & t + 1
Selection.SelectRow
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Next t
ActiveDocument.SaveAs FileName:="store3.doc", FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
Windows("store3.doc").Close
Windows("Arkiv1.doc").Activate
End Sub
Private Sub Gemmer_data_Click()
If Kasse_nr.Text = "" Then
MsgBox "Husk at skrive Kassen navn"
Else
ChangeFileOpenDirectory _
ActiveDocument.Path
Selection.WholeStory
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.SaveAs FileName:=Kasse_nr.Text & ".doc", FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
' Kopier Data
Selection.GoTo What:=wdGoToBookmark, Name:="Afdeling"
Selection.TypeText Text:=Afdeling.Text
Selection.GoTo What:=wdGoToBookmark, Name:="Dato_Initialer"
Selection.TypeText Text:=Dato_Initialer.Text
Selection.GoTo What:=wdGoToBookmark, Name:="Kassationsår"
Selection.TypeText Text:=Kassationsår.Text
Selection.GoTo What:=wdGoToBookmark, Name:="Kasse_nr"
Selection.TypeText Text:=Kasse_nr.Text
Selection.GoTo What:=wdGoToBookmark, Name:="Datoperiode"
Selection.TypeText Text:=Datoperiode.Text
Selection.GoTo What:=wdGoToBookmark, Name:="Titel_Beskrivelse"
Selection.TypeText Text:=Beskrivelse1.Text
Dim Tabel(45) As String
'Celler
Dim TabelData As Variant
TabelData = Array(t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, t6.Text, t7.Text, t8.Text, t9.Text, t10.Text, t11.Text, t12.Text, t13.Text, t14.Text, t15.Text, t16.Text, t17.Text, t18.Text, t19.Text, t20.Text, t21.Text, t22.Text, t23.Text, t24.Text, t25.Text, t26.Text, t27.Text, t28.Text, t29.Text, t30.Text, t31.Text, t32.Text, t33.Text, t34.Text, t35.Text, t36.Text, t37.Text, t38.Text, t39.Text, t40.Text, t41.Text, t42.Text, t43.Text, t44.Text, t45.Text)
Selection.GoTo What:=wdGoToBookmark, Name:="TabelDato1"
Selection.TypeText Text:=TabelData(0)
For t = 0 To 43
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=TabelData(t + 1)
Next t
'Radio
Dim RadioData As Variant
RadioData = Array(r1.Value, r2.Value, r3.Value, r4.Value, r5.Value, r6.Value, r7.Value, r8.Value, r9.Value, r10.Value)
Selection.GoTo What:=wdGoToBookmark, Name:="Kx1"
For t = 0 To 9
If RadioData(t) = True Then
Selection.TypeText Text:="X"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=Beskrivelse2.Text
Selection.MoveLeft Unit:=wdCharacter, Count:=1
End If
Selection.MoveDown Unit:=wdLine, Count:=1
Next t
ActiveDocument.Save
Windows(Kasse_nr.Text & ".doc").Close
Windows("Arkiv1.doc").Activate
End If
End Sub
Private Sub Kasse_nr_Change()
t1.Value = Date$
t4.Value = Date$
t7.Value = Date$
t10.Value = Date$
t13.Value = Date$
t16.Value = Date$
t19.Value = Date$
t22.Value = Date$
t25.Value = Date$
t28.Value = Date$
t31.Value = Date$
t34.Value = Date$
t37.Value = Date$
t40.Value = Date$
t43.Value = Date$
End Sub
Private Sub KopierData_Click()
'Kopier Data
lblDatoperiode.Text = Datoperiode.Text
lblKassenr.Text = Kasse_nr.Text
lblBeskrivelse.Text = Beskrivelse1.Text
lblKassation.Text = Kassationsår.Text
ChangeFileOpenDirectory _
ActiveDocument.Path
End Sub
Private Sub Luk_Click()
Module1.SaveData (Data) ///////////////// FEJL /////////////
End Sub
Private Sub t27_Change()
End Sub
Private Sub UserForm_Click()
End Sub
*************Module1******************
Type ArkivData ' Create user-defined type.
RadioData As Variant
TabelData As Variant
T_Data As Variant
lblDatoperiode As Variant
lblKassenr As Variant
lblBeskrivelse As Variant
lblKassation As Variant
End Type
Sub SaveData(ByRef AData As ArkivData)
Dim fs, f As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.opentextfile("C:\Documents and Settings\Thomas.THOMAS-A0J1R9D4\Skrivebord\Novo Nordisk\Skabelon\testfile.txt", 2, True) ' [Write],[Create file]
For t = 0 To 43
f.Write AData
Next t
f.Close
End Sub
Public Sub Start()
UserForm1.Show
End Sub