The project name is "SaveWord" and the module name is "Toword".There is a function named "UpdateWord" in this module.But when I write the code: set ttt = createobject(saveword.I want to see the function name, but nothing occured. It said"未找到方法或数据成员"What's the matter?? Help me...
The module function is as following:
===========================Public Function UpdateWord(strarr() As Byte) As IntegerDim Wobj As Word.Application
Dim wordDoc As Word.DocumentSet Wobj = CreateObject("Word.Application")Set wordDoc = Wobj.Documents.Open("c:\subject.doc")Wobj.Application.Visible = False
Wobj.Selection.Find.ClearFormatting
Wobj.Selection.Find.Replacement.ClearFormatting
For i = 1 To 10
If IsNull(strarr(i, 1)) = False And strarr(i, 1) <> "" Then
strRep = strarr(i, 2) With Wobj.Selection.Find
.Text = strarr(1, 1)
.Replacement.Text = strRep
.Forward = True
.MatchByte = True
End With
Wobj.Selection.Find.Execute Replace:=wdReplaceAll
End If
Next i
wordDoc.Save
wordDoc.Close
Set wordDoc = Nothing
Set Wobj = Nothingtoword = 1End Function
The module function is as following:
===========================Public Function UpdateWord(strarr() As Byte) As IntegerDim Wobj As Word.Application
Dim wordDoc As Word.DocumentSet Wobj = CreateObject("Word.Application")Set wordDoc = Wobj.Documents.Open("c:\subject.doc")Wobj.Application.Visible = False
Wobj.Selection.Find.ClearFormatting
Wobj.Selection.Find.Replacement.ClearFormatting
For i = 1 To 10
If IsNull(strarr(i, 1)) = False And strarr(i, 1) <> "" Then
strRep = strarr(i, 2) With Wobj.Selection.Find
.Text = strarr(1, 1)
.Replacement.Text = strRep
.Forward = True
.MatchByte = True
End With
Wobj.Selection.Find.Execute Replace:=wdReplaceAll
End If
Next i
wordDoc.Save
wordDoc.Close
Set wordDoc = Nothing
Set Wobj = Nothingtoword = 1End Function
不过老实说,你的Help Me之前的一段话,我不明白你的意思。
你的SaveWord工程是和主工程在一个工程组里面的吗?
You should put the code in a standard, public class in order to be able to create an instance of it and invoke its methods.
Just remember, modules are ALWAYS private.
And, it's recommended to use compile-time-binding (namely, Project->Reference menu setting), rather than run-time-binding (namely, CreateObject, etc.)
那我怎么使module成为public呢?怎么解决"未找到方法或数据成员"这一问题?谁肯把我的代码试验一下呢?
你可以在工程-》引用菜单中引用你的组件,然后声明的对象就可以了。
Module是不会提供类接口的。SaveWord里面没有任何接口可供外部使用。
对象变量或WITH块变量未设置?
===========Private Sub Form_Load()
'Dim tt As Saveword.towordDim aa(2, 2) As String
Dim i As Integer
aa(1, 1) = "Subject"
aa(1, 2) = "menu"Dim tt As towordi = tt.UpdateWord(aa)
End Sub