将数据从Excel表单传递到新电子表格(Passing data from a Excel form to a new spreadsheet)
我在Excel中尝试新的东西。 就像我对VBA一样新,所以请耐心等待。
我有一个包含大量内容的表单..一个项目是一个打开电子表格的按钮。 我想将表单中的信息传递给新打开的电子表格,但是我正在墙上运行。 我做了以下..
在表单顶部声明了一个公共变量
Public instno As String
然后在表单的初始化我从当前工作表中为该字符串赋值。
Sub UserForm_Initialize() instno = Cells(ActiveCell.Row, "J").Value ' other stuff in here too, this is just for this problem... End Sub
现在打开新工作簿的按钮的代码,我试图将值传递给。
Private Sub CMB2_Click() Dim xlApp As Excel.Application Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True xlApp.Workbooks.Open Filename:="G:\tracking.xlsm" Cells(13, "E").Value = instno 'data should go into cell E13 End Sub
对我不起作用,有什么建议吗? 工作簿打开正常,无法将数据输入其中。
I´m trying something new in Excel. Just as new as I am to VBA, so please bear with me.
I have a form with a bunch of things on it.. one item is a button that opens a spreadsheet. I would like to pass information from the form to the newly opened spreadsheet but am running against a wall. I did the following..
Declared a public variable right at the top of the form
Public instno As String
then on the initialization of the form I assign a value to this string from the current worksheet.
Sub UserForm_Initialize() instno = Cells(ActiveCell.Row, "J").Value ' other stuff in here too, this is just for this problem... End Sub
Now the code for the button that opens the new workbook and that I am trying to pass the value to.
Private Sub CMB2_Click() Dim xlApp As Excel.Application Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True xlApp.Workbooks.Open Filename:="G:\tracking.xlsm" Cells(13, "E").Value = instno 'data should go into cell E13 End Sub
Does not work for me, any suggestions ? The workbook opens fine, just can´t get the data into it.
原文:https://stackoverflow.com/questions/16129830
最满意答案
您需要在命令中添加/ c:
System.Diagnostics.Process.Start("cmd.exe", @" /c cd\");
/ c:执行string指定的命令然后终止。
但尝试一些更长的东西,所以你可以看看是否有任何事情发生。
You need to add /c to the command:
System.Diagnostics.Process.Start("cmd.exe", @" /c cd\");
/c : Carries out the command specified by string and then terminates.
But try something a little more lengthy, so you can see if anything happens.
相关问答
更多-
为什么我的查询不执行?(Why doesn't my query execute?)[2023-09-17]
您需要使用反引号来逃避MySQL中的保留字,如password和key INSERT INTO users (username, email, `password`, activated, `key`) VALUES ... You need to escape reserved words in MySQL like password and key with backticks INSERT INTO users (username, email, `password`, activated, `ke ... -
那是因为DataContext没有数据。 绑定表达式返回当前DataContext值。 您可以使用{Binding Converter={StaticResource imageConverter}, Path=Icon}表达式为Image设置DataContext ,或者将其设置为根元素(在您的情况下为UserControl )。 此选项更好,因为您可以使用RelativeSource表达式来避免使用显式名称。如果在确保您正在读取有效的字符串引用之后循环仍然没有运行,那么您应该检查您正在读取的流是否有效。 例如,如果文件不存在或者您没有读取权限,则流将无效。 当流无效时, getline将不会读取任何内容。 它的返回值是相同的流,当转换为bool ,它的计算结果为false 。 在继续之前检查流的状态。 ifstream in("records.txt"); if (!in.is_open()) { std::cerr << "Uh-oh.\n"; return EXIT_FAILURE; } If t ...要立即执行的字符串中的begin end将被视为PL / SQL匿名块。 在PL / SQL中不允许DDL,如COMMENT 。 如果是的话,你不需要立即使用execute。 Oracle基本上可以同时使用PL / SQL语句块或单个SQL语句。 虽然也有批量SQL语句的API。 因此,要在PL / SQL块或过程中运行COMMENT ,您需要execute immediate语句。 如果没有更多的背景,我不能明智地评论这是否是正确的方法,或者只是单独评论这两个评论会更好。 The begin end wi ...在这条线执行时: $(':checkbox[name=selectAll]').change(...); 没有名为selectAll的复选框 - 它在脚本下定义。 将你的代码包装在.ready事件中: $(document).ready(function(){ }); 当DOM层次被完全构建时(简单地说,当浏览器看到