Thema Datum  Von Nutzer Rating
Antwort
02.04.2020 12:11:02 Estelle
*****
NotSolved
03.04.2020 16:41:23 Gast14621
NotSolved
06.04.2020 12:48:19 Gast31315
NotSolved
06.04.2020 22:48:44 Gast14621
NotSolved
06.04.2020 22:56:54 Gast14621
NotSolved
07.04.2020 09:56:16 Gast25041
NotSolved
07.04.2020 13:06:31 Gast95775
NotSolved
07.04.2020 15:03:38 Gast64055
NotSolved
Rot Formatierung in Textmarken mit VBA übernehmen
07.04.2020 16:56:55 Gast55674
NotSolved
08.04.2020 17:12:03 Gast3733
NotSolved
09.04.2020 18:07:16 Gast45089
NotSolved
10.04.2020 19:44:14 Gast14621
NotSolved

Ansicht des Beitrags:
Von:
Gast55674
Datum:
07.04.2020 16:56:55
Views:
763
Rating: Antwort:
  Ja
Thema:
Formatierung in Textmarken mit VBA übernehmen

Hallo,

oha, das sagst Du jetzt...;-)...aber ok, dann macht's Sinn...da müssen wir jeden einzelnen Buchstaben durchnuckeln...

Option Explicit

Private Sub CommandButton1_Click()
   Dim oExcelApp As Object
   Dim oExcelWorkbook As Object
   Dim lZeile As Long
   Dim objRange As Range
   If ListBox1.ListIndex >= 0 Then

         Set oExcelApp = CreateObject("Excel.Application")
         Set oExcelWorkbook = oExcelApp.Workbooks.Open(sBeispiel)

         lZeile = 2
         With oExcelWorkbook.Sheets(sTabellenblatt)
                Do While .Cells(lZeile, 1) <> ""
                    If ListBox1.Text = CStr(.Cells(lZeile, 2).Value) Then
                        Set objRange = ActiveDocument.Bookmarks("test1").Range
                        objRange.Text = CStr(.Cells(1, 2).Value)
                        Call Font_Transfer(probjWdChars:=objRange.Characters, probjXlCell:=.Cells(1, 2))
                        Set objRange = ActiveDocument.Bookmarks("test2").Range
                        objRange.Text = CStr(.Cells(1, 1).Value)
                        Call Font_Transfer(probjWdChars:=objRange.Characters, probjXlCell:=.Cells(1, 1))
                        Set objRange = ActiveDocument.Bookmarks("test3").Range
                        objRange.Text = CStr(.Cells(1, 3).Value)
                        Call Font_Transfer(probjWdChars:=objRange.Characters, probjXlCell:=.Cells(1, 3))
                        Set objRange = Nothing
                        Exit Do
                    End If
                    lZeile = lZeile + 1
                Loop
         End With

         oExcelWorkbook.Close False
         oExcelApp.Quit

     Else
         MsgBox "Bitte wählen Sie einen Eintrag aus der Liste aus!", _
             vbInformation + vbOKOnly, "HINWEIS!"
         Exit Sub
     End If

    Set oExcelWorkbook = Nothing
    Set oExcelApp = Nothing
    Unload Me
End Sub

Private Sub Font_Transfer(ByRef probjWdChars As Characters, ByRef probjXlCell As Object)
Dim objXlFont As Object
Dim lngIndex As Long
With probjXlCell
    For lngIndex = 1 To .Characters.Count
        Set objXlFont = .Characters(Start:=lngIndex, Length:=1).Font
        With probjWdChars.Item(Index:=lngIndex).Font
            .Color = objXlFont.Color
            .Bold = objXlFont.Bold
            .Name = objXlFont.Name
            .Italic = objXlFont.Italic
            .Size = objXlFont.Size
            .Underline = GetFontUnderline(pvlngXlUnderline:=objXlFont.Underline)
        End With
    Next
End With
Set objXlFont = Nothing
End Sub

Private Function GetFontUnderline(ByVal pvlngXlUnderline As Long) As WdUnderline
   Const xlUnderlineStyleNone As Long = -4142
   Const xlUnderlineStyleSingle As Long = 2
   Const xlUnderlineStyleDouble As Long = -4119
   Select Case pvlngXlUnderline
      Case Is = xlUnderlineStyleNone: GetFontUnderline = wdUnderlineNone
      Case Is = xlUnderlineStyleSingle: GetFontUnderline = wdUnderlineSingle
      Case Is = xlUnderlineStyleDouble: GetFontUnderline = wdUnderlineDouble
   End Select
End Function

Gruß,


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
02.04.2020 12:11:02 Estelle
*****
NotSolved
03.04.2020 16:41:23 Gast14621
NotSolved
06.04.2020 12:48:19 Gast31315
NotSolved
06.04.2020 22:48:44 Gast14621
NotSolved
06.04.2020 22:56:54 Gast14621
NotSolved
07.04.2020 09:56:16 Gast25041
NotSolved
07.04.2020 13:06:31 Gast95775
NotSolved
07.04.2020 15:03:38 Gast64055
NotSolved
Rot Formatierung in Textmarken mit VBA übernehmen
07.04.2020 16:56:55 Gast55674
NotSolved
08.04.2020 17:12:03 Gast3733
NotSolved
09.04.2020 18:07:16 Gast45089
NotSolved
10.04.2020 19:44:14 Gast14621
NotSolved