我的代码是ocx中动态生成一个html的元素:file(就是用于上传文件的那个组件,点击“浏览”,选择文件),我的代码是这样写的: Private Sub Command1_Click() Dim inputname As String Dim oDoc As HTMLDocument Dim oFileInput As HTMLFormElement Dim odiv As HTMLDivElement Dim pathname As String inputname = "name1" Dim pathname As stringSet oDoc = New HTMLDocument '生成一个file Set oFileInput = oDoc.createElement("input") oFileInput.setAttribute "name", inputname oFileInput.setAttribute "id", inputname oFileInput.setAttribute "type", "file" oFileInput.outerHTML = "<input type='file' id='" + inputname + "' name='" + inputname + "' >"'打开file oFileInput.click pathname=oFileInput.value debug.print pathname end sub 问题是:我在html里加载这个ocx后,单击“command1”后,没有任何的反应?当然也就得不到pathname的值。另外:我引用的是“Microsoft HTML Object Library”,没有使用“页面设计器”。请高手指点我的代码有什么问题?
Private Sub Command1_Click()
Dim inputname As String
Dim oDoc As HTMLDocument
Dim oFileInput As HTMLFormElement
Dim odiv As HTMLDivElement
Dim pathname As String
inputname = "name1"
Dim pathname As stringSet oDoc = New HTMLDocument
'生成一个file
Set oFileInput = oDoc.createElement("input")
oFileInput.setAttribute "name", inputname
oFileInput.setAttribute "id", inputname
oFileInput.setAttribute "type", "file"
oFileInput.outerHTML = "<input type='file' id='" + inputname + "' name='" + inputname + "' >"'打开file
oFileInput.click
pathname=oFileInput.value
debug.print pathname
end sub
问题是:我在html里加载这个ocx后,单击“command1”后,没有任何的反应?当然也就得不到pathname的值。另外:我引用的是“Microsoft HTML Object Library”,没有使用“页面设计器”。请高手指点我的代码有什么问题?
getelementsbyname