Avatar billede Klaus123 Mester
29. juli 2013 - 16:02 Der er 2 kommentarer og
1 løsning

Ændre fronte i vba

Hej

Jeg har lavet en foreløbig VBA kode i Excel der opretter et Word dokument.

Jeg vil gerne kunne ændre udseendet af teksten, fx fed, kursiv, og hele typografier til fx overskrifter.

----------------------------------------------------
Sub Flet()

Dim Wdapp As Object
Dim Navn As String
Dim Adr As String
Dim PnrBy As String

        Navn = Range("B2").Value
        Adr = Range("B3").Value
        PnrBy = Range("B4").Value & " " & Range("B5").Value
         
        On Error Resume Next
        Set Wdapp = GetObject(, "Word.application")
        If Err.Number <> 0 Then
            Set Wdapp = CreateObject("Word.Application")
        End If

        Wdapp.Documents.Add
        Wdapp.Selection.TypeText Text:=Navn
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeText Text:=Adr
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeText Text:=PnrBy
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeText Text:="Kære " & Left(Navn, InStr(1, Navn, " "))
        Wdapp.Selection.TypeParagraph
       
        Range("a1").Activate

        Wdapp.Visible = True
        Wdapp.Activate

        Set Wdapp = Nothing

End Sub
----------------------------------------------------
Avatar billede store-morten Ekspert
29. juli 2013 - 20:19 #1
Måske:
Sub Flet2()

Dim Wdapp As Object
Dim Navn As String
Dim Adr As String
Dim PnrBy As String

        Navn = Range("B2").Value
        Adr = Range("B3").Value
        PnrBy = Range("B4").Value & " " & Range("B5").Value
         
        On Error Resume Next
        Set Wdapp = GetObject(, "Word.application")
        If Err.Number <> 0 Then
            Set Wdapp = CreateObject("Word.Application")
        End If

        Wdapp.Documents.Add
       
        Wdapp.Selection.Font.Size = 13 'tekst str. 13
        Wdapp.Selection.Font.Bold = True 'Fed til
        Wdapp.Selection.TypeText Text:=Navn
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeText Text:=Adr
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeText Text:=PnrBy
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.Font.Bold = False 'Fed fra
       
        Wdapp.Selection.Font.Size = 11 'tekst str. 11
        Wdapp.Selection.Font.Italic = True 'Kursiv til
        Wdapp.Selection.TypeText Text:="Kære " & Left(Navn, InStr(1, Navn, " "))
        Wdapp.Selection.TypeParagraph
        Wdapp.Selection.Font.Italic = False 'Kursiv fra
       
        Range("a1").Activate

        Wdapp.Visible = True
        Wdapp.Activate

        Set Wdapp = Nothing

End Sub
Avatar billede Klaus123 Mester
01. august 2013 - 08:08 #2
Tak

Det virker som det skal. Ligger du et svar

Kan hele typografier og indholdsfortegnelser indsættes. fx overskrift 1, 2 og 3

Venlig hilsen

Klaus
Avatar billede store-morten Ekspert
01. august 2013 - 15:57 #3
Ved ikke med  typografier ;-(
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester