Hi, again!
First of all big thanks for all the help i am 3 days into this so im asking alot... But hell the answers i get is really awesome, so big thanks for that... Now for the problem.
-----
Im using multiple userforms and a command buttons to print hardcoded and layouted text into my word document. Problem is that it´s really frustrating to do like this i would rather put in a bookmark and just update its value. The problem is not adding the text but deleting it.
Ill post some of my code. i want to get rid of my deleting parts and use updatedbookmarks. That´s more convinient, i think..
Sub UpdateBookmark2(bokmark1 As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(bokmark1).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add bokmark1, BMRange
End Sub
Sub UpdateBookmark(bokmark2 As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(bokmark2).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add bokmark2, BMRange
End Sub
Sub UpdateBookmark3(bokmark3 As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(bokmark3).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add bokmark3, BMRange
End Sub
Private Sub CommandButton1_Click()
' Uppdaterar bokmärkena
UpdateBookmark "bokmark1", TextBox1
UpdateBookmark "bokmark2", "Övervägande"
UpdateBookmark "bokmark3", "Beslut om undantag enligt lag (2007:592) om kassaregister m.m."
'Låser förfrågan knappen
CommandButton1.Enabled = False
CommandButton2.Enabled = True
'Lägger till text
Selection.MoveDown Unit:=wdLine, Count:=3
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Skatteverket överväger att fatta beslut på det sätt som framgår nedan. Ni har möjlighet att lämna synpunkter innan Skatteverket fattar beslut. Kontakta mig gärna om ni undrar över något i detta övervägande. "
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Om ni vill lämna synpunkter ska dessa ha inkommit senast den"
'today´s date + 14 days
Selection.TypeText Text:=" och ska skickas till:"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Kassaregisterfunktionen"
Selection.TypeParagraph
Selection.TypeText Text:="Skattekontor 2 Göteborg"
Selection.TypeParagraph
Selection.TypeText Text:="Box 28 25"
Selection.TypeParagraph
Selection.TypeText Text:="403 20 Göteborg"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Ange handläggarens namn och referensnummer i svaret."
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Övervägande."
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Motivering."
Selection.Font.Bold = wdToggle
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="........................."
Selection.TypeParagraph
Selection.TypeText Text:="Handläggarens namn"
End Sub
Private Sub CommandButton2_Click()
' Tömmer textboxarna från det inskrivna värdet
TextBox1.Text = ""
TextBox2.Text = ""
'Uppdaterar bokmärkena med funktionen updatdatebokmark
UpdateBookmark "bokmark1", ""
UpdateBookmark "bokmark2", "Ärende"
UpdateBookmark "bokmark3", "Ärendemening"
'Låser tabort knappen
CommandButton1.Enabled = True
CommandButton2.Enabled = False
' Tar bort texten
Selection.MoveLeft Unit:=wdCharacter, Count:=18, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=31, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=3
End Sub
Private Sub CommandButton3_Click()
UpdateBookmark "bokmark1", ""
UpdateBookmark "bokmark2", "Ärende"
UpdateBookmark "bokmark3", "Ärendemening"
' Tar bort texten
Selection.MoveLeft Unit:=wdCharacter, Count:=18, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=31, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=3
Unload Me
UserForm2.Show
End Sub
Private Sub CommandButton4_Click()
Unload Me
End Sub
First of all big thanks for all the help i am 3 days into this so im asking alot... But hell the answers i get is really awesome, so big thanks for that... Now for the problem.
-----
Im using multiple userforms and a command buttons to print hardcoded and layouted text into my word document. Problem is that it´s really frustrating to do like this i would rather put in a bookmark and just update its value. The problem is not adding the text but deleting it.
Ill post some of my code. i want to get rid of my deleting parts and use updatedbookmarks. That´s more convinient, i think..
Sub UpdateBookmark2(bokmark1 As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(bokmark1).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add bokmark1, BMRange
End Sub
Sub UpdateBookmark(bokmark2 As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(bokmark2).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add bokmark2, BMRange
End Sub
Sub UpdateBookmark3(bokmark3 As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(bokmark3).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add bokmark3, BMRange
End Sub
Private Sub CommandButton1_Click()
' Uppdaterar bokmärkena
UpdateBookmark "bokmark1", TextBox1
UpdateBookmark "bokmark2", "Övervägande"
UpdateBookmark "bokmark3", "Beslut om undantag enligt lag (2007:592) om kassaregister m.m."
'Låser förfrågan knappen
CommandButton1.Enabled = False
CommandButton2.Enabled = True
'Lägger till text
Selection.MoveDown Unit:=wdLine, Count:=3
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Skatteverket överväger att fatta beslut på det sätt som framgår nedan. Ni har möjlighet att lämna synpunkter innan Skatteverket fattar beslut. Kontakta mig gärna om ni undrar över något i detta övervägande. "
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Om ni vill lämna synpunkter ska dessa ha inkommit senast den"
'today´s date + 14 days
Selection.TypeText Text:=" och ska skickas till:"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Kassaregisterfunktionen"
Selection.TypeParagraph
Selection.TypeText Text:="Skattekontor 2 Göteborg"
Selection.TypeParagraph
Selection.TypeText Text:="Box 28 25"
Selection.TypeParagraph
Selection.TypeText Text:="403 20 Göteborg"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Ange handläggarens namn och referensnummer i svaret."
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Övervägande."
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Motivering."
Selection.Font.Bold = wdToggle
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="........................."
Selection.TypeParagraph
Selection.TypeText Text:="Handläggarens namn"
End Sub
Private Sub CommandButton2_Click()
' Tömmer textboxarna från det inskrivna värdet
TextBox1.Text = ""
TextBox2.Text = ""
'Uppdaterar bokmärkena med funktionen updatdatebokmark
UpdateBookmark "bokmark1", ""
UpdateBookmark "bokmark2", "Ärende"
UpdateBookmark "bokmark3", "Ärendemening"
'Låser tabort knappen
CommandButton1.Enabled = True
CommandButton2.Enabled = False
' Tar bort texten
Selection.MoveLeft Unit:=wdCharacter, Count:=18, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=31, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=3
End Sub
Private Sub CommandButton3_Click()
UpdateBookmark "bokmark1", ""
UpdateBookmark "bokmark2", "Ärende"
UpdateBookmark "bokmark3", "Ärendemening"
' Tar bort texten
Selection.MoveLeft Unit:=wdCharacter, Count:=18, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=31, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=3
Unload Me
UserForm2.Show
End Sub
Private Sub CommandButton4_Click()
Unload Me
End Sub