M$ Word VBA in AutoIt umsetzen

  • Hi Leute, hab da ein verständniss Problem :(

    ich hab da ein VBA Script das ich aus Word Extrahiert habe.

    wie ich es einbinde weis ich auch schon :D

    aber manches weis ich nicht wie ich es umsetzen soll:

    so hier meine Funktion :

    Spoiler anzeigen
    [autoit]

    Func _WordDocPageSetup($objSelection)
    With $objSelection.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = 2.5
    .BottomMargin = 2
    .LeftMargin = 2.5
    .RightMargin = 2.5
    .Gutter = 0
    .HeaderDistance = 1.25
    .FooterDistance = 1.25
    .PaperSize = wdPaperA4
    ;~ .PageWidth =21;;;21
    ;~ .PageHeight = 29.7;;;29,7
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = wdGutterPosLeft
    EndWith
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _FirstTextremove($objSelection)
    $objSelection.MoveDown Unit:= wdLine, Count:= 10, Extend: = wdExtend
    $objSelection.Delete Unit:=wdCharacter, Count: =1
    $objSelection.Find.ClearFormatting
    $objSelection.Find.Replacement.ClearFormatting
    With $objSelection.Find
    .Text = "^p^p^p^p^p^p^p^p^p^p"

    [/autoit] [autoit][/autoit] [autoit]

    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    EndWith
    $objSelection.Find.Execute Replace:=wdReplaceAll
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    bei alle wd..... oder Unit:= ..... schreibt er mir ein syntax error

    wie kann ich das funktionstüchtig machen ??

    danke für die Hilfe
    TOMTOM

    • Offizieller Beitrag
    [autoit]

    $objSelection.MoveDown Unit:= wdLine, Count:= 10, Extend: = wdExtend

    [/autoit]


    Unit, Count, Extend sind Parameter des Word-Selection-Objects, Move-Methode.
    Demzufolge sollte der Aufruf m.E. so aussehen:

    [autoit]

    $objSelection.MoveDown( Unit:= wdLine, Count:= 10, Extend: = wdExtend )

    [/autoit]
  • Zitat

    Original von BugFix

    [autoit]

    $objSelection.MoveDown Unit:= wdLine, Count:= 10, Extend: = wdExtend

    [/autoit]


    Unit, Count, Extend sind Parameter des Word-Selection-Objects, Move-Methode.
    Demzufolge sollte der Aufruf m.E. so aussehen:

    [autoit]

    $objSelection.MoveDown( Unit:= wdLine, Count:= 10, Extend: = wdExtend )

    [/autoit]

    Hallo :)

    leider funzt das nicht so :(

    des hab ich auch schon Probiert :(

    Spoiler anzeigen
    [autoit]

    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(92,41) : ERROR: syntax error
    .Orientation = (wdOrientPortrait)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(100,25) : ERROR: syntax error
    .PaperSize = wdPaperA4
    ~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(103,45) : ERROR: syntax error
    .FirstPageTray = wdPrinterDefaultBin
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(104,46) : ERROR: syntax error
    .OtherPagesTray = wdPrinterDefaultBin
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(105,41) : ERROR: syntax error
    .SectionStart = wdSectionNewPage
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(108,48) : ERROR: syntax error
    .VerticalAlignment = wdAlignVerticalTop
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(115,37) : ERROR: syntax error
    .GutterPos = wdGutterPosLeft
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(119,32) : ERROR: syntax error (illegal character)
    $objSelection.MoveDown (Unit:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(119,61) : ERROR: syntax error (illegal character)
    $objSelection.MoveDown (Unit:= wdLine, Count:= 10, Extend:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(120,31) : ERROR: syntax error (illegal character)
    $objSelection.Delete (Unit:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(128,31) : ERROR: syntax error (illegal character)
    .Wrap = wdFindContinue
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(136,32) : ERROR: syntax error
    $objSelection.Find.Execute Replace
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

    [/autoit]
  • Zitat

    Original von peethebee
    Parameter vielleicht in " " einschließen (also als Strings übergeben)?

    peethebee


    leider nein, hatte ich auch schon mal probiert :(


    Spoiler anzeigen
    [autoit]

    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3(119,68) : ERROR: syntax error
    $objSelection.MoveDown "Unit:=wdLine, Count:=10, Extend:=wdExtend"
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

    [/autoit]
    • Offizieller Beitrag

    Stimmt, war ein Denkfehler. Die Wertzuweisung muß natürlich AutoIt-like erfolgen.
    Also entweder so:

    [autoit]

    $Unit = 'wdLine'
    $Count = 10
    $Extend = 'wdExtend'
    $objSelection.MoveDown( $Unit , $Count, $Extend)

    [/autoit]


    oder so:

    [autoit]

    $objSelection.MoveDown( 'wdLine', 10, 'wdExtend' )

    [/autoit]


    Edit: Lese gerade, das hattest du schon getestet. Hmm... erst mal keine weiteren Ideen. ?(

    Ahhh, aber mit anderer Syntax. Check das mal so.

  • ok gecheckt

    so jetzt bekomm ich die Meldung :

    [autoit]

    D:\9. Scripts_ bestätigung\Bestätigung2PDF.au3 (92) : ==> The requested action with this object has failed.:
    .Orientation = 'wdOrientPortrait'
    .Orientation = 'wdOrientPortrait'^ ERROR

    [/autoit]
  • Ich schicke mal mein kompletes Script:

    evtl zum nachstellen


    Spoiler anzeigen
    [autoit]


    #region --- ScriptWriter generated code Start ---
    Opt("WinWaitDelay", 100)
    Opt("WinTitleMatchMode", 4)
    Opt("WinDetectHiddenText", 1)
    Opt("MouseCoordMode", 0)

    [/autoit] [autoit][/autoit] [autoit]

    #endregion --- ScriptWriter generated code End ---

    [/autoit] [autoit][/autoit] [autoit]

    ;~ #NoTrayIcon
    Local $oDoc
    #include <Word.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Local $Vorlage = "D:\9. Scripts_ bestätigung\Bestätigung live\k0257_vorlagen\Bestätigung_Orient.dot"
    Local $Filepath = "D:\9. Scripts_ bestätigung\Bestätigung live\"
    Local $RRLOGO = "D:\9. Scripts_ bestätigung\Ruefa\Ruefa.jpg"
    Local $s_mode
    Local $oDoc

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(200)
    If WinExists("w_precruefpr.", "") Then
    ExitLoop
    EndIf

    WEnd
    ClipPut("")
    WinWait("w_precruefpr.", "Microsoft Word-Dokument")
    If Not WinActive("w_precruefpr.", "Microsoft Word-Dokument") Then WinActivate("w_precruefpr.", "Microsoft Word-Dokument")
    WinWaitActive("w_precruefpr.", "Microsoft Word-Dokument")
    $handle = WinGetHandle("w_precruefpr.", "Microsoft Word-Dokument")

    [/autoit] [autoit][/autoit] [autoit]

    $oWordApp = _WordAttach($handle, "HWND");;;; das geöffnete word fenster auswählen
    $oDoc = _WordDocGetCollection($oWordApp, 0)
    ;~ If Not @error Then
    ;~ $oDoc = _WordDocGetCollection ($oWordApp, 0)
    ;~ MsgBox(64, "Document FileName", $oDoc.FullName)
    ;~ EndIf
    ;~ Exit
    $objSelection = $oWordApp.Selection
    $my_Text = $objSelection.WholeStory
    ;~ $objSelection.WholeStory ;;;;; Makiere alles
    ;~ $objSelection.Copy ;;; Copiere in die Zwischenablage
    $objSelection.Font.Spacing = 1;;;;adjust the distance between words to 2.5

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;~ _WordDocFind($objSelection, $my_Text);;;look up string
    _WordDocPageSetup($objSelection);;;;_WordDocPageSetup( $objSelection,$PageWidth,$PageHeight)
    _WordDocParagraphFormat($oDoc, $my_Text, 60, 9, 0)

    [/autoit] [autoit][/autoit] [autoit]

    Exit

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _WordDocParagraphFormat($s_oDoc, $s_Text, $s_Color, $s_Size, $s_Number)
    With $oDoc.Range
    .ParagraphFormat.Alignment = 1
    .ParagraphFormat.LineSpacing = 9
    .InsertAfter ($s_Text)
    .Font.Name = "Courier New"
    .Font.Color = $s_Color
    .Font.Size = $s_Size
    .SetRange (0, $s_Number)
    .TwoLinesInOne = 0
    EndWith
    EndFunc ;==>_WordDocParagraphFormat

    [/autoit] [autoit][/autoit] [autoit]

    Func _WordDocPageSetup($objSelection)
    With $objSelection.PageSetup
    .LineNumbering.Active = False
    .Orientation = "wdOrientPortrait"
    .TopMargin = 2.5
    .BottomMargin = 2
    .LeftMargin = 2.5
    .RightMargin = 2.5
    .Gutter = 0
    .HeaderDistance = 1.25
    .FooterDistance = 1.25
    .PaperSize ('wdPaperA4')
    .PageWidth =21;;;21
    .PageHeight = 29.7;;;29,7
    .FirstPageTray = "wdPrinterDefaultBin"
    .OtherPagesTray = "wdPrinterDefaultBin"
    .SectionStart = "wdSectionNewPage"
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = "wdAlignVerticalTop"
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = "wdGutterPosLeft"
    EndWith
    EndFunc ;==>_WordDocPageSetup
    Func _FirstTextremove($objSelection)
    $objSelection.MoveDown ('wdLine',10, 'wdExtend')
    $objSelection.Delete ('wdCharacter',1)
    $objSelection.Find.ClearFormatting
    $objSelection.Find.Replacement.ClearFormatting
    With $objSelection.Find
    .Text = "^p^p^p^p^p^p^p^p^p^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = "wdFindContinue"
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    EndWith
    $objSelection.Find.Execute ('wdReplaceAll')
    EndFunc ;==>_FirstTextremove

    [/autoit] [autoit][/autoit] [autoit]

    Func _WordDocFind($s_objSelection, $s_Text)
    With $s_objSelection.Find
    .Text = $s_Text
    .Execute
    EndWith
    EndFunc ;==>_WordDocFind

    [/autoit]
    • Offizieller Beitrag

    OK, ich denke das klärt einiges.

    "wdOrientPortrait" ist laut MSDN Property von:
    $oWordApp.PageSetup.Orientation

    Du verwendest es aber als Property von:
    $oWordApp.Selection.PageSetup.Orientation

    Somit kann die Aktion für dieses Objekt nicht ausgeführt werden.
    Ich habe jetzt noch nicht weiter geschaut, aber ich vermute auch die anderen Properties sind zumindest teilweise nicht mit den angeführten Methoden kombinierbar.

    Mehr dazu kannst du hier nachlesen.