Question

Table formatting in Word XP

Asked by: NEXPERT-AG

Hi
I have a problem with a template a client uses for invoicing.
The following code works fine for Word97 but not with Word XP:

With Selection.Cells
            With .Borders(wdBorderTop)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
            End With
            With Selection.ParagraphFormat
                .SpaceBefore = 3
            End With
        End With

As soon as the line containing ".LineStyle = wdLineStyleSingle" is executed, the .LineWidth value is 1426064578 which ends up with the following error:

Run-time error '5843':
One of the values passed to this method or property is out of range.

Does any have an idea what I need to change?

Thank you and kind regards
NEXPERT AG

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-08-06 at 08:34:32ID20701655
Topic

Microsoft Office Suite

Participating Experts
1
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Shortcuts in Word97
    Does anybody have a list of shortcuts for Word97 - eg one key response for a bullet list, etc?
  2. Linestyle constant for LegendKey Border
    I am trying to set the legendkey border linestyle, in vba code, to the shaded box that appears under: Format Data Series Patterns Style Some options appear to be xlDot, xlContinuous ... but I can't find the box equivalent as it appears in the drop down list. ....
  3. VB.NET, Word, Paragraphs, Borders
    Does anyone know how I can get the following to work? VB.NET doesn't seem to like to apply borders unless you are dealing with a table although the VB macro editor seems to suggest this is the right way to do this. With objWord.Selection .TypeText("...
  4. Table Borders
    Hi! I'm currently having a trouble in formatting the borders of a table. I already know how to output a table in word from VB but my problem right now is how to set the borders of the table 0 so that my document will appear as if it doesn't have a table. thank you.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: plauwaerPosted on 2003-08-11 at 16:47:54ID: 9126263

If i execute you code. I don't get your problem.

I suggest the following:

With Selection.Cells
        .Borders(wdBorderTop).LineWidth = wdLineWidth050pt
        .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
           With Selection.ParagraphFormat
               .SpaceBefore = 3
           End With
       End With
End Sub

- If this does not solve you problem than may be the problem comes from code that is executed before this code is executed.
Send more code. So i can replicate the error.

Patrick





 

by: NEXPERT-AGPosted on 2003-08-11 at 23:40:50ID: 9127993

Thats part of my problem, if i execute the code alone then it runs fine. In combination with the code before I'll get the error message.  
Here's the complete code - maybe you will find something.

Thanks, NEXPERT AG


Public Sub MAIN()
Dim MacroTitle$
Dim WJ_Chan
Dim PROV$
Dim MANDANT$
Dim FNR$
Dim LNR$
Dim Owner$
Dim MWSTNr$
Dim Bankverb$
Dim Adresse1$
Dim Zeile
Dim RDat$
Dim INT_$
Dim FallNo$
Dim FallName$
Dim RVon$
Dim RBis$
Dim StdHonorar$
Dim StdTotal$
Dim PauschalHonorar$
Dim Betrag$
Dim CPOS$
Dim FixhonTotal$
Dim FixHonText$
Dim FixHonOwner$
Dim FixHonBetrag$
Dim AuslagenTyp$
Dim AuslagenTypText$
Dim AuslagenTypBetrag$
Dim AuslagenTotalBetrag$
Dim AuslagenDetText$
Dim AuslagenDetBetrag$
Dim AuslagenDetDatum$
Dim MWSTCode$
Dim ZTot$
Dim POS$
Dim Anzahl
Dim Anzahl2
Dim MWSTText$
Dim MWSTVon$
Dim MWST$
Dim MWStTotalBetrag
Dim TOTAL2$
Dim Zahlungen
Dim VorausZ$
Dim Dat$
Dim Text_$
Dim SFr$
Dim Zahlungen_$
Dim MWSTBetrag$
Dim RBetrag$
Dim MWSTinkl$
Dim MWStNetto
Dim Z1
Dim MAN$
Dim Typ$
Dim DokName$
Dim ITitel$
Dim Pfad$
Dim LenFNR
Dim LenPfad
Dim Länge
Dim dlg9 As Object
Dim DokTitel$
Dim TM$
Dim Vor$
Dim BetragHON$
Dim FalMwst$

DDETerminateAll

' .......................................................................................................................................................
' START Einfache Auflistung
' .......................................................................................................................................................

'On Error GoTo -1: On Error GoTo ErrorFinish
MacroTitle$ = "WinJur-Rechnung generieren"
StatusBar = "WinJur: Rechnung wird generiert..."

ActiveWindow.ActivePane.View.Type = wdPageView

WJ_Chan = DDEInitiate(App:="WINJUR", Topic:="DDESYSTEM")

DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"

PROV$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_ENTWURF")
MANDANT$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MANDANT")
FNR$ = DDERequest(channel:=WJ_Chan, Item:="LOG_FALL")
Ort$ = DDERequest(channel:=WJ_Chan, Item:="FAL_STANDORT")
Sprache$ = DDERequest(channel:=WJ_Chan, Item:="FAL_SPRACHE")
LNR$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGNO")
WordBasic.FileSummaryInfo Keywords:="WinJur Rechnung=" + FNR$ + LNR$
FalMwst$ = DDERequest(channel:=WJ_Chan, Item:="FAL_MWSTCODE")

' Festlegen der Office Version
Dim OffVer As Integer
OffVer = Left(Application.Build, 2)

'On Error GoTo -1: On Error GoTo SubFehler

'   ADRESSE
    GeheZuTM "Adresse"
    OK$ = DDERequest(channel:=WJ_Chan, Item:="DIV_READREADRESS")
    Adresse$ = DDERequest(channel:=WJ_Chan, Item:="DIV_GETREADRESS")
    While Adresse$ <> ""
        Selection.TypeText Text:=Adresse$
        Adresse$ = DDERequest(channel:=WJ_Chan, Item:="DIV_GETREADRESS")
    Wend

   
'   ORT NACH FALLSTANDORT
    GeheZuTM "Ort"
    If Sprache$ = 0 Then
        If Ort$ = 1 Then
            Ortspez$ = "Basel"
        End If
        If Ort$ = "3" Then
            Ortspez$ = "Bern"
        End If
        If Ort$ = "2" Then
            Ortspez$ = "Küsnacht"
        End If
     ElseIf Sprache$ = 1 Then
        If Ort$ = 1 Then
            Ortspez$ = "Bâle"
        End If
        If Ort$ = 3 Then
            Ortspez$ = "Berne"
        End If
        If Ort$ = 2 Then
            Ortspez$ = "Küsnacht"
        End If
     ElseIf Sprache$ = 2 Then
        If Ort$ = 1 Then
            Ortspez$ = "Basilea"
        End If
        If Ort$ = 3 Then
            Ortspez$ = "Berna"
        End If
        If Ort$ = 2 Then
            Ortspez$ = "Küsnacht"
        End If
     ElseIf Sprache$ = 3 Then
        If Ort$ = 1 Then
            Ortspez$ = "Basel"
        End If
        If Ort$ = 3 Then
            Ortspez$ = "Bern"
        End If
        If Ort$ = 2 Then
            Ortspez$ = "Küsnacht"
        End If
    End If
       
    Selection.TypeText Text:=Ortspez$
   

'   DATUM Datumsformat:T.Monat Jahr
    GeheZuTM "Datum"
    RDat$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")

If OffVer < "9" Then
'    FUER OFFICE 97
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "ANGEBEN """ + RDat$ + """ \@ ""t. MMMM jjjj""", PreserveFormatting:=True
Else
'    FUER OFFICE 2000
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
             "QUOTE """ + RDat$ + """  \@ ""d. MMMM yyyy""", PreserveFormatting:=True
End If

'   INITIALEN
    GeheZuTM "Init"
    Owner_init$ = DDERequest(channel:=WJ_Chan, Item:="FAL_OWNER_INIT")
    Selection.TypeText Text:=Owner_init$ + "/"
   
'   OWNERINIT
    Init$ = DDERequest(channel:=WJ_Chan, Item:="LOG_OWNER_INIT")
    Selection.TypeText Text:=Init$

'   RECHNUNGSNUMMER
    INT_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_OWNER_INIT")
    FallNo$ = DDERequest(channel:=WJ_Chan, Item:="FAL_FALLNO")
    GeheZuTM "Rechnungsnummer"
    Selection.TypeText Text:=FallNo$ + "/R" + LNR$

'   RECHNUNG PROVISORISCH
    If (PROV$ = "1") Then
        GeheZuTM "Provisorisch"
        Selection.TypeText Text:=" Provisorisch"
        GeheZuTM "Prov_Instr"
        Selection.TypeText Text:="Prov_Instr"
        Selection.Range.InsertAutoText
    End If


'   FALLNAMEN
    FallName$ = DDERequest(channel:=WJ_Chan, Item:="FAL_Name")
    GeheZuTM "Fallname"
    Selection.TypeText Text:=FallName$


'   RECHNUNGSPERIODE
    RVon$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_DATUMVON")
    RBis$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_DATUMBIS")
    GeheZuTM "Rechnungsperiode"
'    FUER OFFICE 97
If OffVer < "9" Then
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "ANGEBEN """ + RVon$ + """ \@ ""t. MMMM jjjj""", PreserveFormatting:=True
        Selection.TypeText Text:=" bis "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "ANGEBEN """ + RBis$ + """ \@ ""t. MMMM jjjj""", PreserveFormatting:=True
Else
'    FUER OFFICE 2000
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "Quote """ + RVon$ + """ \@ ""d. MMMM yyyy""", PreserveFormatting:=True
        Selection.TypeText Text:=" bis "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "Quote """ + RBis$ + """ \@ ""d. MMMM yyyy""", PreserveFormatting:=True
End If

'   HONORAR NOTARIAT

        GeheZuTM "Notariat"
        DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_HON_FIRST"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_HON")
        NotariatsZähler = 0
        While POS$ <> "-1"
            Datum$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")
            Std$ = DDERequest(channel:=WJ_Chan, Item:="LOG_HON_STD")
            Init$ = DDERequest(channel:=WJ_Chan, Item:="LOG_OWNER_INIT")
            HonAnsatz$ = DDERequest(channel:=WJ_Chan, Item:="LOG_HON_SATZ")
            Honorar$ = DDERequest(channel:=WJ_Chan, Item:="LOG_HON_TOTAL")
            NotMWST$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
            If Val(Honorar$) <> 0 Then
                Text_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
                SubTyp$ = DDERequest(channel:=WJ_Chan, Item:="LOG_AUS_TYP")
                 If SubTyp$ = 1 Then
                    NotariatsZähler = NotariatsZähler + 1
                    Selection.TypeText Text:=Text_$
                    If FalMwst$ = "1" Or FalMwst$ = "10" Then
                    Else
                     If NotMWST$ = 1 Or NotMWST$ = 10 Then
                         Selection.TypeText Text:=" *)"
                     End If
                    End If
                    Selection.MoveRight Unit:=wdCell
                    Honorar$ = Format(Honorar$, "#,##0.00")
                    BetragNOT$ = Val(BetragNOT$) + Honorar$
                    Honorar$ = Format(Honorar$, "#,##0.00")     '"#,##0.00"
                    Selection.MoveRight Unit:=wdCell
                    Selection.TypeText Text:="CHF" + Chr(9) + Honorar$
                    Selection.MoveRight Unit:=wdCell
                End If
'               21.2.02 Korrektur 1
                If BetragNOT$ = "" Then
                BetragNOT$ = 0
                End If
            End If
            DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_HON_NEXT"
            POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_HON")
        Wend
'               21.2.02 Korrektur 2
            If BetragNOT$ = "" Then
                BetragNOT$ = 0
            End If
            Selection.Rows.Select
            Selection.Rows.Delete
        If NotariatsZähler = 0 Then
            GeheZuTM "Notariat"
            Selection.MoveUp Unit:=wdLine, Count:=1
            Selection.Rows.Select
            Selection.Rows.Delete
        End If
'   HONORAR NOTARIAT checked FS, 18.06.02

    DDEExecute channel:=WJ_Chan, Command:="FORMAT_DOUBLES_ON"

'   HONORAR TOTAL
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    StdHonorar$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_HONORARSTD")
    StdTotal$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_STD")
    SubTyp$ = DDERequest(channel:=WJ_Chan, Item:="LOG_AUS_TYP")
    PauschalHonorar$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_HONORAR")
    BetragHON$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_HONORAR_TOT")
    BetragHON$ = Format(BetragHON$, "#,##0.00")                  '"#,##0.00"
'   21.2.02 Korrektur 3
    Betrag$ = Abs(BetragHON$) - Abs(BetragNOT$)
    GeheZuTM "Honorar"
   
    If Val(Betrag$) <> 0 Then
        Betrag$ = Format(Betrag$, "#,##0.00")                      '"#,##0.00"
        Selection.TypeText Text:="CHF" + Chr(9) + Betrag$
    Else
        Selection.Tables(1).Select
        Selection.Rows.Delete
        Selection.Delete (1)
    End If

    If Val(StdTotal$) <> 0 Or Val(Betrag$) <> 0 Then
'        Selection.MoveRight unit:=wdCell
        ' Selection.TypeText Text:=Chr(9)
        With ActiveDocument.Bookmarks
            .Add Range:=Selection.Range, Name:="Temp"
            .DefaultSorting = wdSortByName
            .ShowHidden = True
        End With
    End If
'   HONORAR TOTAL checked FS, 18.06.02


'   FIXHONORARE
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_FXH_FIRST"
    CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_FXH")
    FixhonTotal$ = DDERequest(channel:=WJ_Chan, Item:="CALC_REC_FIXHONORAR")
    GeheZuTM "Fixhonorar"
    If Val(FixhonTotal$) <> 0 Then
        While (CPOS$ <> "-1")
            FixHonText$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
            FixHonOwner$ = DDERequest(channel:=WJ_Chan, Item:="LOG_OWNER_INIT")
            FixHonBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_FXH_BETRAG")
            FixMWST$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
            Selection.TypeText Text:=FixHonText$
            If FalMwst$ = 1 Or FalMwst$ = 10 Then
            Else
                If FixMWST$ = 1 Or FixMWST$ = 10 Then
                    Selection.TypeText Text:=" *)"
                End If
            End If
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            FixHonBetrag$ = Format(FixHonBetrag$, "#,##0.00") 'Betrag
            Selection.TypeText Text:="CHF" + Chr(9) + FixHonBetrag$
            Selection.MoveRight Unit:=wdCell
            DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_FXH_NEXT"
            CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_FXH")
        Wend
        Selection.SelectRow
        Selection.Rows.Delete
    End If
    If Val(FixHonBetrag$) = 0 Then
        Selection.Tables(1).Select
        Selection.Rows.Delete
        Selection.Delete (1)
    End If
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
   

    If Val(StdTotal$) <> 0 Or Val(Betrag$) <> 0 Then
        With ActiveDocument.Bookmarks
            .Add Range:=Selection.Range, Name:="Temp"
            .DefaultSorting = wdSortByName
            .ShowHidden = True
        End With
    End If
'   FIXHONORARE checked FS, 18.06.02

' MWST Rechnung
'ddeexecute channel:=wj_chan, command:="prep
    DDEExecute channel:=WJ_Chan, Command:="PREPMWSTFOR_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_MWST")
    While (POS$ <> "-1")
        mbez$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BEZEICHNUNG")
        DDEExecute channel:=WJ_Chan, Command:="PREPMWSTFOR_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_MWST")

    Wend

'   Auslagen
    DDEExecute channel:=WJ_Chan, Command:="BUILD_AUS_GROUP_BYNAME"
    DDEExecute channel:=WJ_Chan, Command:="PREPFOR_RE_AUS_GROUP_FIRST"
    CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_GROUP")
     Katbetrag$ = 0
    GeheZuTM "Auslagen"
        Selection.Font.Bold = False
        Selection.Font.Underline = wdUnderlineSingle
        Selection.TypeText Text:="Auslagen"
        Selection.Font.Underline = wdUnderlineNone
        Selection.Font.Bold = False
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell

'       AUSLAGEN PRO KATEGORIE SUMMIERT
        Typ$ = 0
        MCode2$ = 0
        GeheZuTM "RestAuslagen"
        sagcounter = 0   'zählt Stempel, Apostillen, Gericht
       
        While (CPOS$ <> "-1")
            AuslagenTyp$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_DET")
            AuslagenTypText$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_TEXT")
            auslagengrouptyp$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_TYP")
            AuslagenTypBetrag$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_TOTAL")
            MWSTCode$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")      '3.7.02
            MWST$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE")
           
            If AuslagenTyp$ = "0" Then      'Auslage NICHT detailliert
                Typ$ = 0
            ElseIf AuslagenTyp$ = "1" Then  ' Auslage detailliert
                Typ$ = 1
            End If
                ' Porti, Telefon, Telefax aus CodeTab
                If auslagengrouptyp$ = 2 Or auslagengrouptyp$ = 3 Or auslagengrouptyp$ = 4 Then
                    Typ$ = 1
                    AuslagenTypBetrag$ = Format(AuslagenTypBetrag$, "#,##0.00")
                    Katbetrag$ = Val(Katbetrag$) + Val(AuslagenTypBetrag$)
                End If
                '    If AuslagenGroupTyp$ = 3 Then
                '        Typ$ = 1
                '        AuslagenTypBetrag$ = Format(AuslagenTypBetrag$, "#,##0.00")
                '        Katbetrag$ = Val(Katbetrag$) + Val(AuslagenTypBetrag$)
                '    End If
                '    If AuslagenGroupTyp$ = 4 Then
                '        Typ$ = 1
                '        AuslagenTypBetrag$ = Format(AuslagenTypBetrag$, "#,##0.00")
                '        Katbetrag$ = Val(Katbetrag$) + Val(AuslagenTypBetrag$)
                '    End If
           
           If AuslagenTyp$ = "0" Or AuslagenTyp$ = 1 Then
               If Typ$ = 0 Then
                   Selection.TypeText Text:=AuslagenTypText$
                   MCode$ = 0
                   ' Stempel, Apostillen, Gericht aus CodeTab
                   If auslagengrouptyp$ = "10" Or auslagengrouptyp$ = "11" Or auslagengrouptyp$ = "16" Then
                       MCode$ = 1
                       MCode2$ = 1
                   End If
                If MCode$ = 1 Then
                    If FalMwst = "1" Or FalMwst = "10" Then
                    Else
                        Selection.TypeText Text:=" *)"
                    End If
                    sagcounter = sagcounter + 1
                End If
                       '''        MCode2$ = 1
           '''    End If
           '''End If
           Selection.MoveRight Unit:=wdCell
           Selection.MoveRight Unit:=wdCell
           AuslagenTypBetrag$ = Format(AuslagenTypBetrag, "#,##0.00") 'Betrag
           Selection.TypeText Text:="CHF" + Chr(9) + AuslagenTypBetrag$
           Selection.MoveRight Unit:=wdCell
                    End If
            End If
            ''' End If
           DDEExecute channel:=WJ_Chan, Command:="PREPFOR_RE_AUS_GROUP_NEXT"
           CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_GROUP")
        Wend
         
 '      AUSLAGEN MIT DETAILLIERUNG
        DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_AUS_DET_FIRST"
        CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_DET")
        mwstbefr = 0       'Standart MWST Counter für Text ohne Posiitionen mit *)
        mwstausg = 0
       
        While (CPOS$ <> "-1")
                MCode$ = 0
                AusTyp$ = DDERequest(channel:=WJ_Chan, Item:="LOG_AUS_TYP")
                AuslagenDetText$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
                AuslagenDetBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_AUS_TOTAL")
                AuslagenDetDatum$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")
                AuslagenDetTextLeer$ = DDERequest(channel:=WJ_Chan, Item:="LOG_DSPLY_TYP")
                MWSTCode$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
               
                If AuslagenTyp$ = "5" Or AusTyp$ = "7" Or AusTyp$ = "12" Or AusTyp$ = "13" Or AusTyp$ = "14" Then
                    If AuslagenDetText$ <> " " Then
                         Selection.TypeText Text:=AuslagenDetText$
                    End If
                    If AuslagenDetText$ = " " Then
                         Selection.TypeText Text:=AuslagenDetTextLeer$
                    End If
                Else
                    Selection.TypeText Text:=AuslagenDetTextLeer$
                End If
               
                ''' If MWSTCode$ = "0" Then
                '''         MCode$ = 1
                '''         MCode2$ = 1
                ''' End If
                ''' If MWSTCode$ = "1" Then
                '''         MCode$ = 1
                '''         MCode2$ = 1
                ''' End If
                ''' If MWSTCode$ = "10" Then
                '''         MCode$ = 1
                '''         MCode2$ = 1
                ''' End If
                ''' If FalMwst$ = 1 Or FalMwst$ = 10 Then
                ''''Else
                '''     If MCode$ = 1 Then
                '''          Selection.TypeText Text:=" *)"
                '''         MCode2$ = 1
                '''     End If
                ''' End If
                    If FalMwst$ = 1 Or FalMwst$ = 10 Then
                    Else
                        If MWSTCode$ = 1 Or MWSTCode$ = 10 Then
                            Selection.TypeText Text:=" *)"
                        End If
                    End If
                If MWSTCode$ = 1 Then
                    mwstbefr = mwstbefr + 1
                End If
                If MWSTCode$ = 10 Then
                    mwstausg = mwstausg + 1
                End If
               
                Selection.MoveRight Unit:=wdCell
                Selection.MoveRight Unit:=wdCell
                AuslagenDetBetrag$ = Format(AuslagenDetBetrag$, "#,##0.00")
                Selection.TypeText Text:="CHF" + Chr(9) + AuslagenDetBetrag$
                Selection.MoveRight Unit:=wdCell
            DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_AUS_DET_NEXT"
            CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_DET")
        Wend

       
   
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    AuslagenTotalBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_AUSLAGEN")
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
        With Selection.Cells
            With .Borders(wdBorderTop)
                .LineStyle = wdLineStyleSingle
                .LineWidth = wdLineWidth050pt
            End With
            With Selection.ParagraphFormat
                .SpaceBefore = 3
            End With

        End With
       
       
       
       


                     
        AuslagenTotalBetrag$ = Format(AuslagenTotalBetrag$, "#,##0.00") 'Betraq
    Selection.TypeText Text:="CHF" + Chr(9) + AuslagenTotalBetrag$
                 Selection.MoveLeft Unit:=wdCell
    Selection.MoveLeft Unit:=wdCell
    Selection.MoveLeft Unit:=wdCell
    With Selection.Cells
        With Selection.ParagraphFormat
            .SpaceAfter = 3
        End With
    End With


'   Telefon, Fax und Porto als 1. Auslage einfügen
    GeheZuTM "TelFaxPorto"
    If Katbetrag$ <> "0" Then
    Typ$ = 1
    End If
        If Typ$ = 1 Then
            Selection.TypeText Text:="Porti, Telefon, Telefax"
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            Katbetrag$ = Format(Katbetrag$, "#,##0.00")                 '"#,##0.00"
            Selection.TypeText Text:="CHF" + Chr(9) + Katbetrag$
            Selection.MoveRight Unit:=wdCell
        End If
       
        If Katbetrag$ = 0 Then
        GeheZuTM "TelFaxPorto"
            WordBasic.TableSelectRow
            WordBasic.TableDeleteRow
            ' WordBasic.EditClear
        End If

'   Wenn AuslagentotalBetrag durch DDE-Befehl abgerufen werden kann, Rechnungen in den zwei While und naFr.olgende drei Zeile löschen
    If Val(AuslagenTotalBetrag$) = 0 Then
        WordBasic.TableSelectTable
        WordBasic.TableDeleteRow
       '  WordBasic.EditClear
    End If



'   AUFWANDTOTAL MIT AUFLISTUNG MEHRWERTSTEUER
    ZTot$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_TOTAL1")
    GeheZuTM "Zwischentot"
    ZTot$ = Format(ZTot$, "#,##0.00") 'Betrag
    WordBasic.Bold 0
    Selection.TypeText Text:="CHF" + Chr(9) + ZTot$
    WordBasic.Bold 0

    DDEExecute channel:=WJ_Chan, Command:="PREPMWSTFOR_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_MWST")

    GeheZuTM "MWSTText"
    Anzahl = 0
    MWStTotalBetrag = 0

    While (POS$ <> "-1")
        If (Anzahl > 0) Then Selection.MoveRight Unit:=wdCell
        MWSTText$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BEZEICHNUNG")
        MWSTVon$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BETRAG_VON")
        MWST$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BETRAG")
        If Val(MWST$) <> 0 Then
            Anzahl = Anzahl + 1
            Selection.TypeText Text:=MWSTText$
            WordBasic.formatfont 10
            Selection.TypeText Text:=" (Nr. 326202)"
            WordBasic.formatfont 12
              Selection.TypeText Text:=" auf CHF "
              MWSTVon$ = Format(MWSTVon$, "#,##0.00") 'Betrag
              Selection.TypeText Text:=MWSTVon$
            '''If MCode2$ = 1 Then
            If FalMwst$ = 1 Or FalMwst$ = 10 Then
            Else
                If mwstbefr > "0" Or mwstausg > "0" Or sagcounter > 0 Then
                    WordBasic.formatfont 8
                    Selection.TypeText Text:=" ohne Pos. mit *)"
                '''  MCode2$ = 1
                End If
            End If
            WordBasic.formatfont 12
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            MWST$ = Format(MWST$, "#,##0.00") 'Betrag
            Selection.TypeText Text:="CHF" + Chr(9) + MWST$
            MWST$ = Format(MWST$, "###0.00") 'Betrag
            MWStTotalBetrag = MWStTotalBetrag + Val(MWST$)      'Wordbasic.Val
        End If
        DDEExecute channel:=WJ_Chan, Command:="PREPMWSTFOR_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_MWST")
    Wend
        Selection.MoveRight Unit:=wdCell
        WordBasic.TableSelectRow
        WordBasic.TableDeleteRow
 '   End If

    GeheZuTM "ZTotText"
    Selection.Font.Underline = wdUnderlineSingle
    Selection.TypeText Text:="Total Aufwand"
    Selection.Font.Underline = wdUnderlineNone

    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    TOTAL2$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_TOTAL2")
    WordBasic.Bold 0
    GeheZuTM "TotmitMWST"
    TOTAL2$ = Format(TOTAL2$, "#,##0.00") 'Betrag
    WordBasic.Bold 0
    Selection.TypeText Text:="CHF" + Chr(9) + TOTAL2$
    WordBasic.Bold 0

    If Anzahl = 0 And Val(MWST$) = 0 Then
        GeheZuTM "ZwischenTot"
        WordBasic.TableSelectRow
        WordBasic.TableDeleteRow
        'WordBasic.EditClear
    End If


'   KOSTENVORSCHUSS
' fs Kostenvorschuss:
    GeheZuTM "Kostenvorschuss"
    Selection.TypeText Text:="Zahlungsverkehr"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell

    Zahlungen = 0

    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_ZAL_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_ZAL")
    Zahlungen = 0
    While (POS$ <> "-1")
        VorausZ$ = DDERequest(channel:=WJ_Chan, Item:="LOG_ZAL_VORAUSZ")
        If (VorausZ$ = "1") Then
            Dat$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")
            Text_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
            VorsMwst$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
            SFr$ = DDERequest(channel:=WJ_Chan, Item:="LOG_ZAL_TOTAL")
            Zahlungen = Zahlungen + WordBasic.Val(SFr$)
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText Text:="Kostenvorschuss vom "
            Selection.TypeText Text:=Dat$
                If FalMwst$ = 1 Or FalMwst$ = 10 Then
                Else
                    If VorsMwst$ = 1 Or VorsMwst$ = 10 Then
                         Selection.TypeText Text:=" *)"
                    End If
                End If
            Selection.MoveRight Unit:=wdCell
            SFr$ = Format(SFr$, "#,##0.00") 'Betrag
            Selection.TypeText Text:="CHF" + Chr(9) + SFr$
            Zahlungen = Zahlungen + 1
        End If
        DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_ZAL_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_ZAL")
    Wend

    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    Zahlungen_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_ZAHLUNGEN")
    If Zahlungen = 0 Then
        GeheZuTM "Kostenvorschuss"
        WordBasic.TableSelectTable
        WordBasic.TableDeleteCells
        GeheZuTM "ZTotText"
        WordBasic.TableSelectTable
        WordBasic.TableDeleteCells
        WordBasic.EditClear
        WordBasic.EditClear
    End If


'   RECHNUNGSTOTAL
    MWSTBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_MWST")
    RBetrag$ = DDERequest(channel:=WJ_Chan, Item:="CALC_REC_SALDO")
    MWSTinkl$ = DDERequest(channel:=WJ_Chan, Item:="CALC_ZAL_MWST")
    MWStNetto = MWStTotalBetrag - WordBasic.Val(MWSTinkl$)

'    RBetrag$ = Format(RBetrag$, "#,##0.00")                  '"#,##0.00"
    Z1 = Val(RBetrag$)
    GeheZuTM "Saldo"
'    RBetrag$ = Format(RBetrag$, "#,##0.00")                  '"#,##0.00"
    If Z1 > 0 Then
        Selection.Font.Underline = wdUnderlineSingle
        Selection.TypeText Text:="Total zu unseren Gunsten"
        Selection.Font.Underline = wdUnderlineNone
       
        If FalMwst$ = 1 Or FalMwst$ = 10 Then
           If MWSTBetrag$ = 0 Then
               If FalMwst$ = 1 Then
                WordBasic.formatfont 10
                Selection.TypeText Text:=" (MWSt frei)"
            End If
            If FalMwst = 10 Then
                WordBasic.formatfont 10
                Selection.TypeText Text:=" (MWSt ausgenommen)"
            End If
         End If
         Else
            If MWSTBetrag$ = 0 Then
                WordBasic.formatfont 10
                Selection.TypeText Text:=" (MWSt frei)"
            End If
        End If

        Selection.MoveRight Unit:=wdCell
       
        ZelleDoppeltUnterstreichen
       
        If Zahlungen = 0 Then
        Selection.MoveLeft Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
            With Selection.Cells
                With .Borders(wdBorderTop)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                End With
            End With
        End If
        ' RBetrag$ = Abs(Z1)
        RBetrag$ = Format(RBetrag$, "#,##0.00")             '"#,##0.00"
        Selection.TypeText Text:="CHF" + Chr(9) + RBetrag$
'        WordBasic.Bold 0
        WordBasic.TableSelectRow
        WordBasic.FormatParagraph Before:="3 pt"
        WordBasic.FormatParagraph After:="3 pt"
        GeheZuTM "Schluss"
        If Val(MWSTinkl$) <> 0 Then
            Selection.TypeText Text:="Im MWSt-Betrag von CHF "
            MWStTotalBetrag = Format(MWStTotalBetrag, "#,##0.00")       '"#,##0.00"
            Selection.TypeText Text:=(MWStTotalBetrag)
            Selection.TypeText Text:=" sind CHF "
            MWSTinkl$ = Format(MWSTinkl$, "#,##0.00")
            Selection.TypeText Text:=MWSTinkl$
            Selection.TypeText Text:=" MWSt auf Kostenvorschüssen enthalten, so dass sich der Netto-MWSt-Betrag dieser Rechnung auf CHF "
            MWStNetto = Format(MWStNetto, "#,##0.00")                   '"#,##0.00"
            Selection.TypeText Text:=(MWStNetto)
            Selection.TypeText Text:=" beläuft."
            Selection.TypeParagraph
            Selection.TypeParagraph
        End If
    ElseIf Z1 < 0 Then
        Selection.Font.Underline = wdUnderlineSingle
        Selection.TypeText Text:="Total zu Ihren Gunsten"
        Selection.Font.Underline = wdUnderlineNone
        Selection.MoveRight Unit:=wdCell
       
        ZelleDoppeltUnterstreichen
       
        RBetrag$ = Abs(RBetrag$)
        RBetrag$ = Format(RBetrag$, "#,##0.00")                         '"#,##0.00"
        Selection.TypeText Text:="CHF" + Chr(9) + RBetrag$
        WordBasic.TableSelectRow
        GeheZuTM "Schluss"
        If Val(MWSTinkl$) <> 0 Then
            Selection.TypeText Text:="Im MWSt-Betrag von CHF "
            MWStTotalBetrag = Format(MWStTotalBetrag, "#,##0.00")          '"#,##0.00"
            Selection.TypeText Text:=(MWStTotalBetrag)
            Selection.TypeText Text:=" sind CHF "
            MWSTinkl$ = Format(MWSTinkl$, "#,##0.00")
            Selection.TypeText Text:=MWSTinkl$
            Selection.TypeText Text:=" MWSt auf Kostenvorschüssen enthalten, so dass sich der Netto-MWSt-Betrag dieser Rechnung auf CHF "
            MWStNetto = Format(MWStNetto, "#,##0.00")                   '"#,##0.00"
            Selection.TypeText Text:=(MWStNetto)
            Selection.TypeText Text:=" beläuft."
            Selection.TypeParagraph
            Selection.TypeParagraph
        End If
    ElseIf Z1 = 0 Then
        If Vor$ = "1" Then
        Selection.Font.Underline = wdUnderlineSingle
        Selection.TypeText Text:="Total zu Gunsten Ihrer nächsten Rechnung"
        Selection.Font.Underline = wdUnderlineNone
        Selection.MoveRight Unit:=wdCell
       
        ZelleDoppeltUnterstreichen
       
        If RBetrag$ = 0 Then
        TOTAL2$ = Format(TOTAL2$, "#,##0.00")                      '"####0.00"
        RBetrag$ = Val(SFRTOT$) - Val(TOTAL2$)
        RBetrag$ = Abs(RBetrag$)
        End If
        Selection.TypeText Text:="CHF" + Chr(9) + RBetrag$
        WordBasic.TableSelectRow
        WordBasic.EditReplace Find:="-", Replace:="", ReplaceAll:=1
        GeheZuTM "Schluss"
        If Val(MWSTinkl$) <> 0 Then
            Selection.TypeText Text:="Im MWSt-Betrag von CHF "
            MWStTotalBetrag = Format(MWStTotalBetrag, "#,##0.00")   '"#,##0.00"
            Selection.TypeText Text:=(MWStTotalBetrag)
            Selection.TypeText Text:=" sind CHF "
            MWSTinkl$ = Format(MWSTinkl$, "#,##0.00")
            Selection.TypeText Text:=MWSTinkl$
            Selection.TypeText Text:=" MWSt auf Kostenvorschüssen enthalten, so dass sich der Netto-MWSt-Betrag dieser Rechnung auf CHF "
            MWStNetto = Format(MWStNetto, "#,##0.00")               '"#,##0.00"
            Selection.TypeText Text:=(MWStNetto)
            Selection.TypeText Text:=" beläuft."
            Selection.TypeParagraph
            Selection.TypeParagraph
        End If
        Selection.TypeText Text:="Der Saldo von CHF "
        RBetrag$ = Format(RBetrag$, "#,##0.00")                     '"#,##0.00"
        Selection.TypeText Text:=RBetrag$
        Selection.HomeKey Unit:=wdLine
        WordBasic.EditReplace Find:="-", Replace:="", ReplaceAll:=1
        Selection.EndKey Unit:=wdLine
        Selection.TypeText Text:=" wird auf neue Rechnung vorgetragen."
        Selection.HomeKey Unit:=wdLine
        Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend
        Selection.Find.ClearFormatting
        Selection.Find.Execute
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With

        End If
        If Vor$ = "0" Then
        Selection.Font.Underline = wdUnderlineSingle
        Selection.TypeText Text:="Total"
        Selection.Font.Underline = wdUnderlineNone
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
       
        ZelleUnterstreichen
       
        Selection.TypeText Text:="CHF" + Chr(9)
        RBetrag$ = Abs(RBetrag$)
        RBetrag$ = Format(RBetrag$, "#,##0.00")             '"#,##0.00"
        Selection.TypeText Text:=RBetrag$
        Selection.Rows.Select
        With Selection.ParagraphFormat
            .SpaceAfter = 3
        End With
        End If
    End If

' .......................................................................................................................................................
' ENDE Einfache Auflistung
' .......................................................................................................................................................

' .......................................................................................................................................................
' START Detaillierte Auflistung
' .......................................................................................................................................................

'   FALLNAMEN
    GeheZuTM "Rechnungsnummer2"
'    FallName$ = DDERequest(channel:=WJ_Chan, Item:="FAL_NAME")
    FallName$ = DDERequest(channel:=WJ_Chan, Item:="DIV_FAL_WINDOWNAME")
    Selection.TypeText Text:=FallName$
'    Selection.TypeText Text:=INT_$ + "/" + FallNo$ + "/R" + LNR$


'   RECHNUNG PROVISORISCH
    If (PROV$ = "1") Then
        GeheZuTM "Provisorisch2"
        Selection.TypeText Text:="  /  Provisorisch"
    End If



'   RECHNUNGSNUMMER
    GeheZuTM "Fallname2"
    FallNo$ = DDERequest(channel:=WJ_Chan, Item:="FAL_FALLNO")
    Selection.TypeText Text:=FallNo$ + "/R" + LNR$


'   RECHNUNGSPERIODE
    RVon$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_DATUMVON")
    RBis$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_DATUMBIS")
    GeheZuTM "Rechnungsperiode2"
    Selection.TypeText Text:=RVon$ + " bis "
    Selection.TypeText Text:=RBis$

'   HONORAR DETAILLIERT
    honcounter = 0
    mwstfalsch = 0
    StdHonorar$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_HONORARSTD")
    StdTotal$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_STD")
    PauschalHonorar$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_HONORAR")
    HonorarTotalBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_HONORAR_TOT")
   
   
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_HON_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_HON")
    GeheZuTM "Honorar2"
    While POS$ <> "-1"
        Datum$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")
        Std$ = DDERequest(channel:=WJ_Chan, Item:="LOG_HON_STD")
        Init$ = DDERequest(channel:=WJ_Chan, Item:="LOG_OWNER_INIT")
        HonAnsatz$ = DDERequest(channel:=WJ_Chan, Item:="LOG_HON_SATZ")
        Honorar$ = DDERequest(channel:=WJ_Chan, Item:="LOG_HON_TOTAL")
        honmwstcode$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
        HonAnsatz$ = Format(HonAnsatz$, "#,##0.00") 'Betrag
        Honorar$ = Format(Honorar$, "#,##0.00") 'Betrag
        If Val(Honorar$) <> 0 Then
            Selection.TypeText Text:=Datum$
            Selection.MoveRight Unit:=wdCell
            EndWhile = 0
            While EndWhile = 0
                Text_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
                If Text_$ = "" Then
                    EndWhile = 1
                Else
                    Selection.TypeText Text:=Text_$
                End If
            Wend
            If FalMwst$ = 1 Or FalMwst$ = 10 Then
            Else
                If honmwstcode$ = "1" Or honmwstcode$ = 10 Then 'VorsMwst$ = "10" Then
                    Selection.TypeText Text:=" *)"
                Else
                    honcounter = honcounter + 1
                End If
            End If
            Selection.MoveRight Unit:=wdCell
            If Val(Std$) > 0 Then
'                Std$ = Format(Std$, "##0.0")
                Selection.TypeText Text:=Std$
                Selection.MoveRight Unit:=wdCell
                Selection.TypeText Text:=Init$
                Else
                Selection.MoveRight Unit:=wdCell
            End If
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText Text:=HonAnsatz$
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText Text:="CHF" + Chr(9) + Honorar$
            Selection.MoveRight Unit:=wdCell
            If honmwstcode$ = MWSTCodeText$ Then
            Else
                Selection.MoveUp Unit:=wdLine, Count:=1
                Selection.SelectRow
'                Selection.Font.Bold = True
'                Selection.MoveRight unit:=wdCell
                Selection.MoveDown Unit:=wdLine, Count:=1
                mwstfalsch = 1
            End If
        End If
        DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_HON_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_HON")
    Wend

    If Val(StdTotal$) > 0 Or Val(HonorarTotalBetrag$) > 0 Then
        Selection.Font.Bold = True
        Selection.TypeText Text:="Total Leistungen"
        Selection.Font.Bold = False
        Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
        Selection.Cells.Merge
        Selection.MoveRight Unit:=wdCell
        If Val(StdTotal$) > 0 Then
'            StdTotal$ = Format(StdTotal$, "##0.0")
            Selection.Font.Bold = True
            Selection.TypeText Text:=StdTotal$
            Selection.Font.Bold = False
        End If
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        HonorarTotalBetrag$ = Format(HonorarTotalBetrag$, "#,##0.00") 'Betrag
        Selection.Font.Bold = True
        Selection.TypeText Text:="CHF" + Chr(9) + HonorarTotalBetrag$
        Selection.Font.Bold = False
        Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
        Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
        With Selection.Borders(wdBorderTop)
            .LineStyle = Options.DefaultBorderLineStyle
            .LineWidth = Options.DefaultBorderLineWidth
        End With
        Selection.SelectRow
        With Selection.ParagraphFormat
            .SpaceBefore = 3
            .SpaceAfter = 3
        End With
    Else
        Selection.Tables(1).Select
        Selection.Cells.Delete
        Selection.Characters(1).Select
        Selection.Delete
        Selection.MoveUp
        Selection.Delete Unit:=wdCharacter, Count:=1
    End If


'   FIXHONORARE
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_FXH_FIRST"
    CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_FXH")
    FixhonTotal$ = DDERequest(channel:=WJ_Chan, Item:="CALC_REC_FIXHONORAR")
    GeheZuTM "Fixhonorar2"
    If Val(FixhonTotal$) <> 0 Then
        While (CPOS$ <> "-1")
            FixHonText$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
            FixHonOwner$ = DDERequest(channel:=WJ_Chan, Item:="LOG_OWNER_INIT")
            FixHonBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_FXH_BETRAG")
            FixMWStCode$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
            Selection.TypeText Text:=FixHonText$
            If FalMwst$ = 1 Or FalMwst$ = 10 Then
            Else
                If FixMWStCode$ = 1 Or FixMWStCode$ = 10 Then
                    Selection.TypeText Text:=" *)"
                End If
            End If
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            FixHonBetrag$ = Format(FixHonBetrag$, "#,##0.00") 'Betrag
            Selection.TypeText Text:="CHF" + Chr(9) + FixHonBetrag$
            Selection.MoveRight Unit:=wdCell
            DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_FXH_NEXT"
            CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_FXH")
        Wend
        Selection.SelectRow
        Selection.Rows.Delete
    ElseIf Val(FixHonBetrag$) = 0 Then
        Selection.Tables(1).Select
        Selection.Rows.Delete
        Selection.Delete (1)
    End If
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"


'   Auslagen
    DDEExecute channel:=WJ_Chan, Command:="BUILD_AUS_GROUP_BYNAME"
    DDEExecute channel:=WJ_Chan, Command:="PREPFOR_RE_AUS_GROUP_FIRST"
    CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_GROUP")

    GeheZuTM "Löschbar2"
        Selection.Font.Bold = True
        Selection.TypeText Text:="Barauslagen"
        Selection.Font.Bold = False
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        Selection.Font.Bold = False

        ' AUSLAGEN PRO KATEGORIE SUMMIERT
        While (CPOS$ <> "-1")
            AuslagenTyp$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_DET")
            AuslagenTypText$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_TEXT")
            AuslagenTypBetrag$ = DDERequest(channel:=WJ_Chan, Item:="GROUP_TOTAL")
            auslagengrouptyp$ = DDERequest(channel:=WJ_Chan, Item:="Group_Typ")
            AuslagenTypBetrag$ = Format(AuslagenTypBetrag$, "#,##0.00") 'Betrag
            If AuslagenTyp$ = "0" Then
                Selection.TypeText Text:="- " + AuslagenTypText$
                MCode$ = 0
                    ' frage
                If auslagengrouptyp$ = "10" Or auslagengrouptyp$ = "11" Or auslagengrouptyp$ = 16 Then
                    MCode$ = 1
                    MCode2$ = 1
                End If
                If FalMwst$ = 1 Or FalMwst$ = 10 Then
                Else
                    If MCode$ = 1 Then
                        Selection.TypeText Text:=" *)"
                        MCode2$ = 1
                    End If
                End If
                Selection.MoveRight Unit:=wdCell
                AuslagenTypBetrag$ = Format(AuslagenTypBetrag$, "#,##0.00")
                Selection.TypeText Text:="CHF" + Chr(9) + AuslagenTypBetrag$
                Selection.MoveRight Unit:=wdCell
                Selection.MoveRight Unit:=wdCell
            End If
            DDEExecute channel:=WJ_Chan, Command:="PREPFOR_RE_AUS_GROUP_NEXT"
            CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_GROUP")
        Wend
 
' AUSLAGEN MIT DETAILLIERUNG
        DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_AUS_DET_FIRST"
        CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_DET")
        MCode$ = 0

       
        While (CPOS$ <> "-1")
            AusTyp$ = DDERequest(channel:=WJ_Chan, Item:="LOG_AUS_TYP")
            AuslagenDetText$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
            AuslagenDetBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_AUS_TOTAL")
            AuslagenDetDatum$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")
            AuslagenDetTextLeer$ = DDERequest(channel:=WJ_Chan, Item:="LOG_DSPLY_TYP")
            MWSTCode$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
            If AuslagenTyp$ = "5" Or AusTyp$ = "7" Or AuslTyp$ = "12" Or AusTyp$ = "13" Or AusTyp$ = "14" Then
                If AuslagenDetText$ <> " " Then
                     Selection.TypeText Text:=AuslagenDetText$
                End If
                If AuslagenDetText$ = " " Then
                     Selection.TypeText Text:=AuslagenDetTextLeer$
                End If
            Else
                Selection.TypeText Text:=AuslagenDetTextLeer$
            End If
            If MWSTCode$ = "0" Then
                    MCode$ = 1
                    MCode2$ = 1
            End If
            If MWSTCode$ = "1" Then
                    MCode$ = 1
                    MCode2$ = 1
            End If
            If MWSTCode$ = "10" Then
                    MCode$ = 1
                    MCode2$ = 1
            End If
            If FalMwst$ = 1 Or FalMwst$ = 10 Then
            Else
                If MCode$ = 1 Then
                    If MWSTCode$ = 1 Or MWSTCode$ = 10 Then
                        Selection.TypeText Text:=" *)"
                    End If
                End If
            End If
            Selection.MoveRight Unit:=wdCell
            AuslagenDetBetrag$ = Format(AuslagenDetBetrag$, "#,##0.00")
            Selection.TypeText Text:="CHF" + Chr(9) + AuslagenDetBetrag$
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_AUS_DET_NEXT"
            CPOS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_AUS_DET")
            MCode$ = 0
        Wend

        Selection.Rows.Delete
        Selection.MoveLeft Count:=3
       
        ZelleUnterstreichen
       
        Selection.MoveRight Unit:=wdCell
       
        ZelleUnterstreichen
   
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    AuslagenTotalBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_AUSLAGEN")
    AuslagenTotalBetrag$ = Format(AuslagenTotalBetrag$, "#,##0.00") 'Betrag
    Selection.TypeText Text:="CHF" + Chr(9) + AuslagenTotalBetrag$

'   Wenn AuslagentotalBetrag durch DDE-Befehl abgerufen werden kann, Rechnungen in den zwei While und naCHFolgende drei Zeile löschen
    If Val(AuslagenTotalBetrag$) = 0 Then
        WordBasic.TableSelectTable
        WordBasic.TableDeleteRow
        WordBasic.EditClear
    End If


'   AUFWANDTOTAL MIT AUFLISTUNG MEHRWERTSTEUER
    ZTot$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_TOTAL1")
    ZTot$ = Format(ZTot$, "#,##0.00") 'Betrag
    GeheZuTM "Zwischentot2"
    WordBasic.Bold 1
    Selection.TypeText Text:="CHF" + Chr(9) + ZTot$
    WordBasic.Bold 0

    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    DDEExecute channel:=WJ_Chan, Command:="PREPMWSTFOR_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_MWST")

    GeheZuTM "MWSTText2"
    Anzahl = 0
   
   
    '''If FalMwst$ = "1" Or FalMwst$ = "10" Then
    '''        Selection.TypeText Text:="MWSt-frei"
    '''Else
        While (POS$ <> "-1")
            If (Anzahl > 1) Then Selection.MoveRight Unit:=wdCell
             MWSTText$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BEZEICHNUNG")
             MWSTVon$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BETRAG_VON")
             MWST$ = DDERequest(channel:=WJ_Chan, Item:="MWST_BETRAG")
             If Val(MWST$) <> 0 Then
                Anzahl = Anzahl + 1
                If (Anzahl > 1) Then Selection.MoveRight Unit:=wdCell
                    Selection.TypeText Text:=MWSTText$
                    WordBasic.formatfont 10
                    Selection.TypeText Text:=" (Nr. 326202)"
                    WordBasic.formatfont 12
                    Selection.TypeText Text:=" auf CHF "
                    MWSTVon$ = Format(MWSTVon$, "#,##0.00") 'Betrag
                    Selection.TypeText Text:=MWSTVon$
                '''If MCode2$ = 1 Then
                    If FalMwst$ = 1 Or FalMwst$ = 10 Then
                    Else
                        If mwstbefr > 0 Or mwstausg > 0 Or sagcounter > 0 Then
                            WordBasic.formatfont 8
                            Selection.TypeText Text:=" ohne Pos. mit *)"
                            MCode2$ = 1
                        End If
                    End If
                'End If
            'End If
            WordBasic.formatfont 12
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            MWST$ = Format(MWST$, "#,##0.00") 'Betrag
            Selection.TypeText Text:="CHF" + Chr(9) + MWST$
            ' MWStTotalBetrag = MWStTotalBetrag + WordBasic.Val(MWST$)      'Deaktiviert am 9.1.02,FS
      End If
        DDEExecute channel:=WJ_Chan, Command:="PREPMWSTFOR_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_MWST")
    ''''End If
    Wend
    '''End If
'''End If
   
Mwsttot$ = DDERequest(channel:=WJ_Chan, Item:="Log_REC_MWST")
Mwsttot = Val(Mwsttot$)
'    If Mwsttot = "0" Then
'        GeheZuTM "MWSTText2"
'        WordBasic.TableSelectRow
'        WordBasic.TableDeleteRow
'        WordBasic.EditClear
'    End If
       

    ' Letzen Eintrag unterstreichen
    If Mwsttot = "0" Then
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
    End If
'        If MCode2$ = 1 Then
'        Selection.MoveLeft unit:=wdCell
'        End If
    If (Anzahl > 1) Then
        Selection.MoveLeft Unit:=wdCell
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
    End If
       
        ZelleUnterstreichen

       
       
    GeheZuTM "ZTotText2"
    Selection.Font.Bold = True
    Selection.TypeText Text:="Total inkl. MWSt"
    Selection.Font.Bold = False
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    TOTAL2$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_TOTAL2")
    WordBasic.Bold 0
    GeheZuTM "TotmitMWST2"
    TOTAL2$ = Format(TOTAL2$, "#,##0.00") 'Betrag
    WordBasic.Bold 1
    Selection.TypeText Text:="CHF" + Chr(9) + TOTAL2$
    WordBasic.Bold 0

'    If Anzahl = 0 And Val(MWST$) = 0 Then
'        GeheZuTM "ZwischenTot2"
'        WordBasic.TableSelectRow
'        WordBasic.TableDeleteRow
'        WordBasic.EditClear
'    End If


'   KOSTENVORSCHUSS
' fs Kostenvorschuss2:
    GeheZuTM "Kostenvorschuss2"
    WordBasic.Bold 1
    Selection.TypeText Text:="Zahlungsverkehr"
    WordBasic.Bold 0
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell

    Zahlungen = 0

    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_ZAL_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_ZAL")
    Zahlungen = 0
   
   
   
    While (POS$ <> "-1")
        VorausZ$ = DDERequest(channel:=WJ_Chan, Item:="LOG_ZAL_VORAUSZ")
        If (VorausZ$ = "1") Then
            Dat$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")
            Text_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGTEXT")
            SFr$ = DDERequest(channel:=WJ_Chan, Item:="LOG_ZAL_TOTAL")
            VorsMwst2$ = DDERequest(channel:=WJ_Chan, Item:="LOG_MWSTCODE_NUM")
            Zahlungen = Zahlungen + WordBasic.Val(SFr$)
            Selection.MoveRight Unit:=wdCell
            WordBasic.Bold 0
            Selection.TypeText Text:="Kostenvorschuss vom "
            Selection.TypeText Text:=Dat$
            If FalMwst$ = 1 Or FalMwst$ = 10 Then
            Else
                    If VorsMwst2$ = 1 Or VorsMwst2$ = 10 Then
                         Selection.TypeText Text:=" *)"
                    End If
                End If
            Selection.MoveRight Unit:=wdCell
            Selection.MoveRight Unit:=wdCell
            SFr$ = Format(SFr$, "#,##0.00") 'Betrag
            Selection.TypeText Text:="CHF" + Chr(9) + SFr$
            Zahlungen = Zahlungen + 1
        End If
        DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RE_ZAL_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="GETPOS_RE_ZAL")
    Wend

    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_RECHNUNG"
    Zahlungen_$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_ZAHLUNGEN")
   
    ZelleUnterstreichen
   
    If Zahlungen = 0 Then
        GeheZuTM "Kostenvorschuss2"
        WordBasic.TableSelectTable
        WordBasic.TableDeleteCells
        GeheZuTM "ZTotText2"
        WordBasic.TableSelectTable
        WordBasic.TableDeleteCells
        WordBasic.EditClear
        WordBasic.EditClear
    End If


'   RECHNUNGSTOTAL
    MWSTBetrag$ = DDERequest(channel:=WJ_Chan, Item:="LOG_REC_MWST")
    RBetrag$ = DDERequest(channel:=WJ_Chan, Item:="CALC_REC_SALDO")
    MWSTinkl$ = DDERequest(channel:=WJ_Chan, Item:="CALC_ZAL_MWST")
   
    DDEExecute channel:=WJ_Chan, Command:="FORMAT_DOUBLES_OFF"
    MWSTinkl2$ = DDERequest(channel:=WJ_Chan, Item:="CALC_ZAL_MWST")
    DDEExecute channel:=WJ_Chan, Command:="FORMAT_DOUBLES_ON"
    MWStNetto = MWStTotalBetrag - WordBasic.Val(MWSTinkl2$)

    Z1 = Val(RBetrag$)
    GeheZuTM "Saldo2"
    If Z1 > 0 Then
        WordBasic.Bold 1
        Selection.TypeText Text:="Total zu unseren Gunsten"
        WordBasic.Bold 0
       
    If FalMwst$ = 1 Or FalMwst$ = 10 Then
        If MWSTBetrag$ = 0 Then
            If FalMwst$ = 1 Then
                WordBasic.formatfont 10
                Selection.TypeText Text:=" (MWSt frei)"
            End If
            If FalMwst = 10 Then
                WordBasic.formatfont 10
                Selection.TypeText Text:=" (MWSt ausgenommen)"
            End If
        End If
        Else
            If MWSTBetrag$ = 0 Then
                WordBasic.formatfont 10
                Selection.TypeText Text:=" (MWSt frei)"
            End If
    End If

        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
       
        ZelleDoppeltUnterstreichen
       
        RBetrag$ = Format(RBetrag$, "#,##0.00") 'Betrag
        WordBasic.Bold 1
        Selection.TypeText Text:="CHF" + Chr(9) + RBetrag$
        WordBasic.Bold 0
        WordBasic.TableSelectRow
        WordBasic.FormatParagraph After:="3 pt"
    Else
        WordBasic.Bold 1
        Selection.TypeText Text:="Total zu Ihren Gunsten"
        WordBasic.Bold 0
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
       
        ZelleDoppeltUnterstreichen
       
        WordBasic.Bold 1
        Selection.TypeText Text:="CHF" + Chr(9) + RBetrag$
        WordBasic.Bold 0
        WordBasic.TableSelectRow
        WordBasic.EditReplace Find:="-", Replace:="", ReplaceAll:=1
    End If
   
'   HONORARTOTALAUFSTELLUNG PRO ANWALT
    DDEExecute channel:=WJ_Chan, Command:="PREPFOR_REHUSER_FIRST"
    POS$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERNAME")
    GeheZuTM "Mitarbeiter"
    While POS$ <> "<End>"
        UserName$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERNAME")
        UserInit$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERINIT")
        userstd$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERSTD")
        Userhon$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERHONORAR")
        UserAnsatz$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERANSATZ")
'        UserAuslagen$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERAUSLAGEN")
'        zugehöriger DDE-Befehl fehlt noch, muss später eingebaut werden
        UserTotalBetrag$ = Userhon$ + UserAuslagen$
'       21.2.02 Korrektur 4
        userstd$ = Format(userstd$, "# ##0.00")                     '"#,##0.0"
        Userhon$ = Format(Userhon$, "#,##0.00")                    '"#,##0.0"
        UserAnsatz$ = Format(UserAnsatz$, "#,##0.00")              '"#,##0.0"
        UserTotalBetrag$ = Format(UserTotalBetrag$, "#,##0.00")     '"#,##0.0"
        Selection.TypeText Text:=UserInit$
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:=userstd$
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:=Userhon$
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:=UserAnsatz$
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:=UserAuslagen$
        Selection.MoveRight Unit:=wdCell
        Selection.TypeText Text:=UserTotalBetrag$
        Selection.MoveRight Unit:=wdCell
        DDEExecute channel:=WJ_Chan, Command:="PREPFOR_REHUSER_NEXT"
        POS$ = DDERequest(channel:=WJ_Chan, Item:="REHUSERNAME")
    Wend
    Selection.MoveRight Unit:=wdCell
    With Selection.Cells
        With .Borders(wdBorderTop)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth050pt
        End With
    End With
    If Val(StdTotal$) <> 0 Then Selection.TypeText Text:=StdTotal$
    Selection.MoveRight Unit:=wdCell
    With Selection.Cells
        With .Borders(wdBorderTop)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth050pt
        End With
    End With
    If Val(HonorarTotalBetrag$) <> 0 Then Selection.TypeText Text:=HonorarTotalBetrag$
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    If Val(AuslagenTotalBetrag$) <> 0 Then Selection.TypeText Text:=AuslagenTotalBetrag$
    Selection.MoveRight Unit:=wdCell
        With Selection.Cells
        With .Borders(wdBorderTop)
            .LineStyle = wdLineStyleSingle
            .LineWidth = wdLineWidth050pt
        End With
    End With
    If Val(ZTot$) <> 0 Then Selection.TypeText Text:=ZTot$ 'Betrag stimmt
   
    Selection.SelectRow
    With Selection.ParagraphFormat
        .SpaceBefore = 3
        .SpaceAfter = 3
    End With

'   ORT/DATUM/INITIALEN
    GeheZuTM "Ort2"
    Selection.TypeText Text:=Ortspez$
    GeheZuTM "Datum2"
    RDat$ = DDERequest(channel:=WJ_Chan, Item:="LOG_LOGDATUM")

If OffVer < "9" Then
'    FUER OFFICE 97
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "ANGEBEN """ + RDat$ + """ \@ ""t. MMMM jjjj""", PreserveFormatting:=True
'    FUER OFFICE 2000
Else
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "QUOTE """ + RDat$ + """  \@ ""d. MMMM yyyy""", PreserveFormatting:=True
End If

     GeheZuTM "Init2"
     Selection.TypeText Text:=Owner_init$ + "/" + Init

GeheZuTM "Bankverbindung"
Bank
RechnungFertig:

WordBasic.StartOfDocument
ActiveWindow.View.Type = wdPageView
Selection.HomeKey Unit:=wdStory

' .......................................................................................................................................................
' ENDE Detaillierte Auflistung
' .......................................................................................................................................................

'   OHNE SPEICHERN
    Z1 = Val(LNR$)
    If Z1 = 0 Then GoTo Finish2
    If (PROV$ = "1") Then GoTo Finish2
   
'   AUTOM. DATEISPEICHERUNG
    LNR$ = "000000" + LNR$
    MAN$ = DDERequest(channel:=WJ_Chan, Item:="FAL_MANDANT")
   
    Typ$ = "R0"
    DokName$ = Typ$ + Right(LNR$, 8) + ".doc"
    Call SetDocProperties(DokName$)
    DDEPoke channel:=WJ_Chan, Item:="SET_POKEFALLNO", Data:=FNR$
    Pfad$ = DDERequest(channel:=WJ_Chan, Item:="DIV_GETDOCDIR")
    LenFNR = Len(FNR$)
    LenPfad = Len(Pfad$)
    LENPfad1 = LenPfad - LenFNR
    Pfad$ = Left(Pfad$, LENPfad1)
    Pfad$ = Pfad$ + FNR$
    DocFullName$ = Pfad$ + Application.PathSeparator + DokName$
    If Dir(Pfad$, vbDirectory) = "" Then
        MkDir Pfad$
    End If
   
    ActiveDocument.SaveAs FileName:=DocFullName$
   
    ' Defining Logtext of Invoice in WinJur
   
    If IsDate(RVon$) = True Then
        RVon$ = Format(RVon$, "d.m.yyyy")
    End If
    If IsDate(RBis$) = True Then
        RBis$ = Format(RBis$, "d.m.yyyy")
    End If
    Str_InvLogtext = "RG: " & RVon$ & "  -  " & RBis$
   
    DDEPoke channel:=WJ_Chan, Item:="SET_POKEMANDANT", Data:=MAN$
    DDEPoke channel:=WJ_Chan, Item:="SET_POKELOGNO", Data:=LNR$
    DDEPoke channel:=WJ_Chan, Item:="LOG_DOKUMENTNAME", Data:=ActiveDocument.Name
    DDEPoke channel:=WJ_Chan, Item:="LOG_PATHNAME", Data:=ActiveDocument.Path
    DDEPoke channel:=WJ_Chan, Item:="LOG_LOGTEXT", Data:=Str_InvLogtext
       
    GoTo Cont

SubFehler:
    CheckError Err.Number, TM$
Cont:
   
   
ErrorFinish:
Finish2:
    DDEExecute channel:=WJ_Chan, Command:="DESTROY_RECHNUNG"
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_NOTHING"
    DDETerminate channel:=WJ_Chan
    StatusBar = "WinJur Ok"
    GoTo Exit_
Finish1:
    DDEExecute channel:=WJ_Chan, Command:="DESTROY_RECHNUNG"
    DDEExecute channel:=WJ_Chan, Command:="PREPLOGFOR_NOTHING"
    DDETerminate channel:=WJ_Chan
    StatusBar = "WinJur Macro not Ok"
    GoTo Exit_
   
Exit_:
End Sub

Private Sub GeheZuTM(TextMarke$)
Dim TM$
        TM$ = TextMarke$
        If WordBasic.ExistingBookmark(TM$) Then
            Selection.GoTo What:=wdGoToBookmark, Name:=TM$
        Else
            WordBasic.MsgBox "Textmarke: " + TM$, "Fehlende Textmarke"
            CheckError 1005, TM$
        End If
End Sub

Private Sub CheckError(Err_, TM$)
Dim Continue
'-----------------------

Select Case Err_

Case 1005
    WordBasic.MsgBox "Textmarke: " + TM$, "Fehlende Textmarke"

Case Else
    WordBasic.MsgBox "WordBasic Error: " + Str(Err_), "WJDCC/WinWord Fehler"


End Select

Err_ = 0
Continue = 0
DDETerminateAll


End Sub

Public Static Sub Bank()
    Load UserForm1
    UserForm1.Show
End Sub

Public Sub UserForm_Initialize()
    Load UserForm1
    UserForm1.Show
End Sub

Public Sub doku()
        GeheZuTM "Bankverbindung"
        Unload UserForm1
End Sub

Public Sub divers()
    Dim Prompt
    Dim Bankverbindung
    Prompt = "Bitte geben Sie hier ihre Bankverbindung ein."
   
    Bankverbindung = InputBox(Prompt)
'   MsgBox (Bankverbindung), , "Eingabe"
    GeheZuTM "Bankverbindung"
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    Selection.Font.Bold = False
    Selection.Font.Underline = wdUnderlineSingle
    Selection.TypeText Text:="Bankverbindung:"
    Selection.Font.Underline = wdUnderlineNone
    Selection.TypeText Text:=Chr(11)
    Selection.TypeText Bankverbindung
End Sub

Sub SetDocProperties(DokName$)
    Dim dp As Object
    Set dp = ActiveDocument.BuiltInDocumentProperties
    dp("Title") = DokName$
    dp("KeyWords") = "WinJur"
End Sub

Public Sub ZelleUnterstreichen()
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
    With Selection.Font
        .Underline = wdUnderlineSingle
        .UnderlineColor = wdColorAutomatic
        .Color = wdColorAutomatic
    End With
End Sub

Public Sub ZelleDoppeltUnterstreichen()
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
    With Selection.Font
        .Underline = wdUnderlineDouble
        .UnderlineColor = wdColorAutomatic
        .Color = wdColorAutomatic
    End With
End Sub

 

by: plauwaerPosted on 2003-08-12 at 04:38:28ID: 9129101

Its a little bit difficult to make your code run, because the code depends on a lot of things.

Question: did you try the code-change i suggested? It was not clear to me in you comment if you have done this.

An other thing that you can try and which can serve as a work-around. Disable Error-handeling for a few lines.

  'Disable errorhandling
  On Error Resume Next  

  With .Borders(wdBorderTop)
               .LineStyle = wdLineStyleSingle
               .LineWidth = wdLineWidth050pt
           End With
           With Selection.ParagraphFormat
               .SpaceBefore = 3
           End With
  End With

  'Enable errorhandling
  On Error GoTo 0


Patrick

 

by: NEXPERT-AGPosted on 2003-08-12 at 04:53:51ID: 9129178

Hi Patrick

The first code did'nt worked too.... It's strange it seems to be a problem with the code before. If I record a macro and execute it in the same place it works. However as soon as the code run's embedded in the whole macro it crashes.
Unfortunately disabling the error handle is not an option in this case.

NEXPERT-AG

 

by: plauwaerPosted on 2003-08-12 at 05:45:50ID: 9129482

Hi NEXPERT-AG

Can you explain why 'temporary' disabling is not an option? The 'disalbling' is controlled, only for a few lines, so i don't see the problem.

Patrick

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...