Visual Fox Pro Word自动化

时间:2019-05-17 07:27:12

标签: vba ms-word visual-foxpro

LOCAL oWord, oDocument, oRange, Lc_start, Lc_expr, Lc_ris, Ln_count, Lc_val
DIMENSION Lc_funct[1]

Lc_expr = ""
Ln_count = 1

oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .T.
cFile = GETFILE()

oDoc = oWord.Documents.Add(m.cFile)

oRange = oWord.ActiveDocument.Range()
    nWordCount = oRange.Words.Count
    oRange.Collapse(1)
    FOR nWord = 1 TO m.nWordCount-1
    oRange.Expand(2)
    cWord = oRange.Text
    DO CASE

    CASE m.cWord = "<|<"
        Lc_start = .T.
        Lc_Expr = ""

    CASE m.cWord = ">|>"
        Lc_start = .F.
        Lc_funct[Ln_count] = Lc_Expr
        Ln_count = Ln_count + 1
        DIMENSION Lc_funct[Ln_count]

    CASE m.Lc_start
        Lc_expr = Lc_expr + m.cWord

    OTHERWISE
        *don't do anything

    ENDCASE

    oRange.Collapse(0)
    ENDFOR


    FOR i = 1 TO Ln_count-1
    oRange = oWord.ActiveDocument.Range()
        oRange.Find.Text = Lc_funct[i]
        oRange.Find.Replacement.Text = EVALUATE(Lc_funct[i])
        lFound = oRange.Find.Execute( , , , , , , , , , , 2 )
    ENDFOR

    FOR i = 1 TO Ln_count-1
    oRange = oWord.ActiveDocument.Range()
        oRange.Find.Text = "<|<"
        oRange.Find.Replacement.Text = ""
        lFound = oRange.Find.Execute( , , , , , , , , , , 2 )
    ENDFOR

    FOR i = 1 TO Ln_count-1
        oRange = oWord.ActiveDocument.Range()
        oRange.Find.Text = ">|>"
        oRange.Find.Replacement.Text = ""
        lFound = oRange.Find.Execute( , , , , , , , , , , 2 )
    ENDFOR
MESSAGEBOX("DONE")

大家好。我编写了这段代码以从Visual Fox Pro自动执行Word。我在转义符“ <| <”和“> |>”之间插入了一些VFP代码(例如从表中获取一些值等等)。按下按钮,代码将扫描所有文档,并在找到这些转义符时评估它们之间的结构。最后两个FOR消除转义字符串。

该代码有效,但是我问。有什么更好的方法可以满足我的需求?

还有,如果我有一个表,是否有一种方法可以在自动化之前确定要在Word文档中传递哪些列?

0 个答案:

没有答案