Einzelnen Beitrag anzeigen

Benutzerbild von gordon freeman
gordon freeman

Registriert seit: 28. Jun 2003
Ort: Gelsenkirchen
337 Beiträge
 
Delphi 2005 Personal
 
#9

Re: *.doc aufteilen...

  Alt 10. Feb 2004, 11:17
Hier der "neue" Code:

Code:
Dim FirstPos, SecPos, a, c, d As Integer
Dim E As String

Private Sub CommandButton1_Click()
a = CInt(TextBox1.Text)
b = TextBox2.Text
c = 0
d = 0
markieren
End Sub

Sub markieren()
While c = 0

d = d + 1


FirstPos = -1
SecPos = -1

ActiveDocument.Range(0, 0).Select

Do While FirstPos = -1 Or SecPos = -1
    With Selection.Find
        .ClearFormatting
        .Font.Size = a
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    If Not Selection.Find.Found Then
     c = 1                                                                                    2)
     Exit Do
    End If
   
    If FirstPos = -1 Then
      FirstPos = Selection.Start
    ElseIf SecPos = -1 Then
      SecPos = Selection.Start
    End If
Loop

If FirstPos <> -1 And SecPos <> -1 Then
  Selection.Start = FirstPos
  Selection.End = SecPos
End If

If c = 0 Then                                                                                1)                

Selection.Cut                                                                                3)
Documents.Add Template:="", NewTemplate:=False, DocumentType:=1
Selection.Paste

E = Str(d)

ChangeFileOpenDirectory "C:\martin\HTML\"
    ActiveDocument.SaveAs FileName:=E + ".htm", FileFormat:=wdFormatHTML, _
        LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False

        ActiveWindow.Close

Else

Selection.WholeStory

Selection.Cut
Documents.Add Template:="", NewTemplate:=False, DocumentType:=1
Selection.Paste

E = Str(d)

ChangeFileOpenDirectory "C:\martin\HTML\"
    ActiveDocument.SaveAs FileName:=E + ".htm", FileFormat:=wdFormatHTML, _
        LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False

        ActiveWindow.Close

End If
Wend
End Sub
1) Der Rechner fragt an der Stelle

Code:
If c = 0 Then
2) ab, ob etwas markiert wurde. Dies soll widerum an der Stelle:

Code:
If Not Selection.Find.Found Then
     c = 1
     Exit Do
    End If
3) festgelegt werden. Allerdings übergeht der Rechner diese Abfrage und Gibt bei

Code:
Selection.Cut
eine Exception aus, da nichts markiert wurde und er somit nichts ausschneiden kann. Falls aber nichts markiert wurde sollte der Rechner eigentlich das gesamte Dokument markieren:

Code:
Else

Selection.WholeStory

Wieso tut er das nicht

bua, tia, cu gordon
  Mit Zitat antworten Zitat