2016-08-31 7 views
1

私はMacを使用しており、会社のアカウントを準備しています。私がMicrosoft Wordで作ったすべてのペイプリップはバウチャー番号を持っています。取引が見落とされたため、すべての伝票番号が間違っていますので、数百の間違った給与があります。Word文書へのグレープアップルスクリプトの自動化

^Vch.+\r 

と何も(それによって、全体の文章を削除する)に置き換えます。私は、次のGREP(:VCH、\ rをするまでの任意の文字、段落の先頭を見つけ、テキスト)を見つけることができるスクリプトを作成します。

私はApplescriptを使用してドキュメントを開いたり、GREPの検索(難しい部分)を実行したり、ドキュメントを保存したり、pdf(必要なものすべて)として保存することを考えていました。

しかし、明らかに私の知識は私を失敗させます。 create range、execute findなどの辞書のコマンドはすべてエラーを返します。私は、スクリプトを考案助けることができるのAppleScriptで経験

誰か?助言がありますか?それは次のようなものでなければなりません:

Tell application "Microsoft Word" 
    tell active document 
    set myRange to create range start 0 end 0 
    tell myRange 
     execute find find "^Vch.+\r" replace with "" 
    end tell 
    end tell 
end tell 

多くの感謝!

答えて

1

行の先頭を示すための特別な文字はありません。あなたは真の

match wildcardsプロパティを設定すると

段落の先頭に検索するには、スクリプトがあなたが段落記号として「^P」を使用することができますが、それは動作しませんreturn & "some text"

を使用する必要があります。

は、スクリプトがreturn & "some text" & returnを使用する必要があり、段落全体を一致させるには、スクリプトではなく、2の1段落記号を削除するためにreplace with returnを使用する必要があります。

最初の段落は、段落記号で始まらないので、スクリプトは2つのexecute findコマンドを使用する必要があります。

ワイルドカード*


tell application "Microsoft Word" -- (tested on version 15.25, Microsoft Office 2016) 

    -- check the first paragraph 
    select (characters of paragraph 1 of active document) 
    execute find (find object of selection) find text ("Vch*" & return) replace with "" replace replace one wrap find find stop with match wildcards and match case without match forward and find format 

    --to search forward toward the end of the document. 
    execute find (find object of selection) find text (return & "Vch*" & return) replace with return replace replace all wrap find find continue with match wildcards, match case and match forward without find format 

    save active document 

    -- export to PDF in the same directory as the active document 
    set pdfPath to path of active document & ":" & (get name of active window) & ".pdf" 
    set pdfPath to my createFile(pdfPath) -- create an empty file if not exists, the handler return a path of type alias (to avoid grant access issue) 
    save as active document file name pdfPath file format format PDF 
end tell 

on createFile(f) 
    do shell script "touch " & quoted form of POSIX path of f 
    return f as alias 
end createFile 
です
関連する問題