1

私は仕事で何かをするように頼まれました。Windows ではなく Ubuntu を実行しているので、Libre Office を持っています (LO Writer は Word に相当します)。- タスクは、いくつかの契約を自動化することです。ドキュメントは、ドキュメントごとに変更されるいくつかの変数を除いて、90% は同じままです。

まず第一に、基本は悪夢であり、一般的に、このマクロ作成プロセス全体もかなりひどいものです。

「コード」に進みます-エラーが発生し続けますがBASIC error: Argument is not optional 、私がやろうとしているのは、2つの配列を別の関数に渡すことだけです:

Function test ( ByVal changeFrom() As String ,ByVal changeTo() As String  )
Dim I As Long
Dim Doc As Object
Dim Replace As Object

Doc = ThisComponent

Replace = Doc.createReplaceDescriptor
For I = 0 To 2
  Replace.SearchString = changeFrom(I) //Error is here
  Replace.ReplaceString = changeTo(I)
  Doc.replaceAll(Replace)
Next I
End Function


REM  *****  BASIC  *****
Sub main
Dim changeFrom(3) As String
Dim changeTo(3) As String


changeFrom() = Array("<word2>", "<word3>", "<word1>")
changeTo() = Array("value1", "value2", "value3")
test( changeFrom , changeTo)
End Sub

一般的 -

本当に私を夢中にさせている「基本」以外に、これを行うためのより良い方法を知っている人はいますか.. Pythonで実行できることは理解していますが、もっと簡単な方法があればいいのにと思います。問題はWord文書ですテーブルと定義する必要があるものがあるため、テンプレートをコピーしてJavaクラスに貼り付けて変更することはできません..

ありがとう!

4

2 に答える 2

1

パラメータが値渡しであると述べたとしても、配列は常に参照として渡されると思います。これがまだ正しいことを確認する必要がありますが、90% 確実と言えます。

提供された回答は、LBound と UBound を適切に使用して、渡された配列に設定されている制限のみを使用します。これはおそらくあなたの問題の最大の部分です。そうは言っても、単純にマクロを作成して、次のようなことを行うことができます。

Function test1 (Doc, changeFrom, changeTo)
Dim I As Long
Dim Replace As Object

' A paranoid person would verify the parameters. Things like:
' Are the parameters NOT IsEmpty and Not IsNull
' Is the Doc object really a text document
' Are the other parameters really arrays

Replace = Doc.createReplaceDescriptor
For I = lbound(changefrom) To ubound(changefrom)
  Replace.SearchString = changeFrom(I)
  Replace.ReplaceString = changeTo(I)
  Doc.replaceAll(Replace)
Next I
End Function


REM  *****  BASIC  *****
Sub main1
  test1(ThisComponent, Array("<word2>", "<word3>", "<word1>"), Array("value1", "value2", "value3"))
End Sub
于 2015-10-29T13:02:54.200 に答える