首页 \ 问答 \ 将数据从Excel表单传递到新电子表格(Passing data from a Excel form to a new spreadsheet)

将数据从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
更新时间:2022-06-22 14:06

最满意答案

您需要在命令中添加/ 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.

相关问答

更多
  • 您需要使用反引号来逃避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层次被完全构建时(简单地说,当浏览器看到 ),事件触发。 By the time this line executes: $(':checkbox[name=selectAll]').change(...); Th ...
  • 这是因为您的Response.Redirect将控件重定向到另一个页面,该页面将忽略您的RegisterScript 。 你需要做的是,如果你试图在按钮点击(更新按钮)中实现这一点,然后在Page_Load尝试 if(!IsPostBack) { btnUpdate.Attributes.Add("OnClick","confirm('Are you sure?');"); } 然后上面的代码可以更改为 if (ReviewExist(StoreID, UserID) != 0) { U ...
  • 最可能的解释是pCellTower也没有设置。 它可以包含随机位,并最终指向分配给应用程序的内存之外。 操作系统不允许你的程序在分配给它的空间之外进行写操作,因此它会向程序发送一些消息(Windows:异常,Unix / Linux:信号),表示写入被拒绝。 The most likely explanation is that pCellTower isn't set either. It could contain random bits, and end up pointing outside the ...
  • 有几个原因可能会显示为文本而不是执行。 首先,它缺少标签。 如果没有这些,PHP会认为您只是想将此文件中的所有内容发送到浏览器。 如果您使用的是Apache,您需要告诉Apache执行这些文件(通常您会告诉Apache执行所有以PHP解释器为结尾的.php文件)。 您的主机可能会要求您将所有可执行文件放在特定的目录中。 确保你按照他们的说明设置网站。 There are several reasons this might be displayed as text rather than e ...
  • 你的javascript工作正常。 BAU文本会转到控制台日志 - 但您必须注意它的运行位置。 它在浏览器中的javascript中,因此它所访问的控制台日志是浏览器控制台日志,而不是node.js控制台日志。 例如,如果您在FireFox中,则可以转到Tools / Web Developer / Browser Console查看javascript的输出。 在我的Mac上,它用你的html显示以下内容,第一行显示正确地来自html文件中的第18行: 当我执行您的脚本时,我在浏览器中看到以下内容。 您将 ...
  • 您需要在命令中添加/ 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)