我正在尝试自动填充一些带有宏的Excel表格数据。现在这个Excel被保护了,我无法获取秘钥。虽然我可以运行宏,但当我尝试传递参数时,出现了参数不匹配的问题。
如果我只运行该宏的名称,会得到一个inputbox
,需要额外的参数作为输入,并自动生成某些列的值。目前,我必须手动将这个值输入到inputbox
中。有没有办法自动化这个过程,即捕获由vb.net脚本引发的宏弹出框,并从那里输入值?也就是说,我想运行该宏,在弹出提示要求输入某个值后,使用vb.net代码向该弹出框输入值。
以下是我迄今为止所拥有的:
Public Class Form1
Dim excelApp As New Excel.Application
Dim excelWorkbook As Excel.Workbook
Dim excelWorkSheet As Excel.Worksheet
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
excelWorkbook = excelApp.Workbooks.Open("D:/excelSheets/plan_management_data_templates_network.xls")
excelApp.Visible = True
excelWorkSheet = excelWorkbook.Sheets("Networks")
With excelWorkSheet
.Range("B7").Value = "AR"
End With
excelApp.Run("createNetworks")
// now here I would like to enter the value into the createNetworks Popup box
excelApp.Quit()
releaseObject(excelApp)
releaseObject(excelWorkbook)
End Sub
宏定义
createNetworks()
//does so basic comparisons on existing populated fields
//if true prompts an inputbox and waits for user input.
这也阻塞了我的 VB.NET 脚本继续执行下一行。
A = Inputbox("这是提示", "这是标题", "这里是输入框中的默认值")
? - Kazimierz Jawor