简体   繁体   English

Excel VBA - 将每个单元分别复制并粘贴到另一个程序

[英]Excel VBA - Copy and Paste each cell Individually to another program

I'm fairly new to VBA but know my way around it a bit (sorta).我对 VBA 还很陌生,但对它有点了解(有点)。 What I'm needing to do is get a Macro set to copy data in one cell, switch to another program (2315), enter "6", [ENTER], paste the data, [ENTER] switch back to Excel, select the next row, copy, switch, paste, switch, until it reaches the end of the column.我需要做的是获取一个宏集来复制一个单元格中的数据,切换到另一个程序(2315),输入“6”,[ENTER],粘贴数据,[ENTER]切换回Excel,select下一行,复制,切换,粘贴,切换,直到它到达列的末尾。 This is what I have, which works for the first cell.这就是我所拥有的,适用于第一个单元格。 I just need to figure out how to loop it until it reaches the end.我只需要弄清楚如何循环它直到它到达终点。 Thanks for any help/suggestions!感谢您的任何帮助/建议!

Range("A2").Select
Selection.Copy
AppActivate "2315"
Application.SendKeys "6~^V~"
Application.SendKeys "%{TAB}"

Thanks Again!再次感谢!

I doubt that this works, but you say it does and your question is about the loop.我怀疑这行得通,但你说它行得通,你的问题是关于循环的。 Here is the loop.这是循环。

Dim R       As Long

For R = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    Cells(R, "A").Copy
    AppActivate "2315"
    Application.SendKeys "6~^V~"
    Application.SendKeys "%{TAB}"
Next R

For Excel's sake you don't need to select anything.为了 Excel,您不需要 select 任何东西。 The above code will loop through all the used cells in column A of the active tab.上面的代码将遍历活动选项卡的 A 列中所有使用的单元格。 If your app "2315" needs the selection, add Cells(R, "A").Select before the copy instruction.如果您的应用程序“2315”需要选择,请在复制指令之前添加Cells(R, "A").Select

My doubt is based in the fact that you can't use VBA to send parameters to app "2315".我的怀疑是基于您不能使用 VBA 将参数发送到应用程序“2315”的事实。 This includes the instruction to "2315" to surrender control back to Excel and its VBA.这包括指令“2315”将控制权交还给 Excel 及其 VBA。 Perhaps you have found such a way via the SendKeys.也许您已经通过 SendKeys 找到了这种方法。 If so, the code will work.如果是这样,代码将起作用。 If not, it will get stuck after the first loop.如果不是,它将在第一个循环后卡住。

Logically, the code should run until AppActivate "2315", meaning the SendKeys are never sent until the other app has returned control.从逻辑上讲,代码应该一直运行到 AppActivate “2315”,这意味着在其他应用程序返回控制权之前永远不会发送 SendKeys。 If that is what's going on there must be better ways to express whatever your two instructions get done.如果这是正在发生的事情,那么必须有更好的方式来表达你完成的两条指令。 But that shouldn't be your immediate concern.但这不应该是你的直接关注。 If you can get "2315" to surrender control back to Excel with a simple command like Enter , and if the above macro really resumes work where it left off, most of your problem should be solved.如果您可以使用Enter之类的简单命令让“2315”将控制权交还给 Excel,并且如果上述宏真的从中断的地方恢复工作,那么您的大部分问题都应该得到解决。 This I hope for:-)我希望这个:-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel VBA复制/粘贴范围到另一个工作表中的下一个可用单元格 - Excel VBA Copy/Paste Range to the next available cell in another worksheet Excel VBA将特定的单元格复制并粘贴到另一个工作表 - Excel VBA copy and paste a specific cell to another Sheet Excel VBA:从另一个工作簿循环中复制和粘贴特定单元格 - Excel VBA: Copy and Paste Specific Cell from Another Workbook Loop Excel VBA 在更改单元格时剪切或复制并粘贴 - Excel VBA Cut or copy and paste on change of cell VBA复制并粘贴一个单元格与另一个单元格 - vba copy and paste one cell vs another VBA用于将文本从单个未移动的单元格复制到粘贴到另一个单元格,每个粘贴/循环向下移动一个单元格 - VBA function to copy text from a single un-moving cell to paste to another cell, moving down one cell each paste/loop 在每个工作表匹配的单元格上复制一个单元格并将其粘贴到另一个VBA - Copy a cell on one sheet and paste it on another VBA based on cell from each sheet matching Excel VBA,如果单元格不是数字且列中为空,则选定单元格复制并粘贴到另一列 - Excel VBA, If cell is not numeric and empty in a column, selected cell copy and paste to another column VBA Excel-复制单元格值并将值粘贴在另一个单元格的字符之间 - VBA Excel - copy cell values and paste value in between characters of another cell Excel VBA宏复制单元格并粘贴到另一个 - Excel vba macro to copy cells and paste in another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM