使用VBA将工作表复制到其他工作簿(Copying a worksheet to another workbook using VBA)
我试图从工作簿复制VBA所在的工作表(ThisWorkbook),并将其过滤到用户已打开的另一工作簿(ActiveWorkbook)中。 我已经写了一个函数,但我无法让它工作。 我之前做过类似的事情,而且我搜索了互联网,但是我找不到解决方案或者为什么它会让我失望。 我究竟做错了什么?
Function workBooks() As String aWbkName = ActiveWorkbook.Name tWbkName = ThisWorkbook.Name Dim wbk1 As Workbook Dim wbk2 As Workbook Set wbk1 = tWbkName Set wbk2 = aWbkName wbk1.Sheet2.Copy After:=wbk2.Sheets(7) End Function
I am trying to copy a worksheet from the workbook that the VBA is in (ThisWorkbook) and past it into another workbook that the user has open (ActiveWorkbook). I have written a function but I cannot get it to work. I have done something similar before and I have searched the internet but I cannot find a solution or why it is failing me. What am I doing wrong?
Function workBooks() As String aWbkName = ActiveWorkbook.Name tWbkName = ThisWorkbook.Name Dim wbk1 As Workbook Dim wbk2 As Workbook Set wbk1 = tWbkName Set wbk2 = aWbkName wbk1.Sheet2.Copy After:=wbk2.Sheets(7) End Function
原文:https://stackoverflow.com/questions/43266597
最满意答案
你有这个问题:
my $RawSequence = loadSequence("~/LDTest.rtf");
而不是使用波浪号给出文件的完整路径:
my $RawSequence = loadSequence("path/to/LDTest.rtf");
或者如果您在同一目录中(意味着如果您从文件所在的同一目录运行程序),只需提供文件名:
my $RawSequence = loadSequence("LDTest.rtf");
You have problem in this line:
my $RawSequence = loadSequence("~/LDTest.rtf");
Instead of using tilde give the full path of the file:
my $RawSequence = loadSequence("path/to/LDTest.rtf");
or if you are in the same directory (meaning if you are running your program from the same directory where the file exists), just give the file name:
my $RawSequence = loadSequence("LDTest.rtf");
相关问答
更多-
如果Perl中的文件中存在特定的正则表达式,如何获取文件名(How to get the filename if particular regexp is present in the file in Perl)[2023-07-25]
你的例子听起来比你的shell单行更复杂。 这相当于perl中的单行: perl -nlwe 'if (/mytext/) { print $ARGV; close ARGV }' * -n打开文件和阅读内容。 -l添加换行符(为方便起见)。 如果找到文本,我们关闭文件句柄以避免打印多个匹配项。 如果要处理更多文件,它将再次打开。 Your examples sound way more complicated than your shell one-liner. This is equivalent t ... -
没有这样的文件或目录,从perl打开“〜/ filename”(No such file or directory, opening “~/filename” from perl)[2024-03-04]
你有这个问题: my $RawSequence = loadSequence("~/LDTest.rtf"); 而不是使用波浪号给出文件的完整路径: my $RawSequence = loadSequence("path/to/LDTest.rtf"); 或者如果您在同一目录中(意味着如果您从文件所在的同一目录运行程序),只需提供文件名: my $RawSequence = loadSequence("LDTest.rtf"); You have problem in this line: my $ ... -
主目录的~别名是shell-ism(shell为你所做的),而不是你可以用Python open命令的东西: pax:~$ cd ~ pax:~$ ls qq.s qq.s pax:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> open ...
-
操作系统。 Perl对-e (以及其他类似-s )的调用是通过调用C库函数stat 。 没有shell "cat some_file" ,因此不会执行"cat some_file" 。 相反,操作系统会查找名为“cat some_file”的文件。 当然, stat可以用相对路径名称来调用。 如果你不想那样,那么除去文件名+扩展名之外的所有东西。 有这种东西的Perl模块 。 我不想调试/查看你提出的正则表达式,因为它确实是完全不可读和不可维护的。 The operating system does. Pe ...
-
shell正在执行分词。 如果您的awk脚本返回空,则"${d}".txt参数将最终为$ARGV[1]或$ARGV[0] 。 如果您的awk脚本返回一个包含空格的字符串,它将最终向下... 为了避免这种情况,你应该引用它们,如下所示: "`awk ...`" 更好的是: "$(awk ...)" The shell is performing word splitting. If your awk scripts return empty, the "${d}".txt parameter will e ...
-
使用替换从输入文件名中删除“.txt”。 使用字符串连接来构建输出文件名: my $infile = 'infile1.txt'; my $prefix = $infile; $prefix =~ s/\.txt//; # remove the '.txt', notice the '\' before the dot # concatenate the prefix and the output filenames my $outfile1 = $prefix."_outfile1.txt"; my ...
-
正确的方法是使用词法文件句柄的open参数形式(模式作为单独的参数)。 也die大写D 喜欢这个 open my $out, '>', $OutputFileName or die $!; 但是你的最后一个例子应该可以工作,假设你已经在你的实际代码中拼写正确拼写。 如果您提供的路径不存在,那么您还需要创建中间目录。 骰子串会告诉你确切的问题。 当这个失败时你会得到什么信息? The proper way is to use the three-parameter form of open (with th ...
-
你非常接近,你只是遇到了一些问题。 首先,那些方括号正在改变你的正则表达式的含义。 一对方括号定义了一个“字符类” - 这是一组匹配的字符。 如果找到任何一个字符,正则表达式将匹配。 所以你正在寻找'c'或'o'或'm'等等。这显然不是你想要的。 所以失去这些括号。 $foundFile = grep(/comapnyABC/i, readdir Dir); 但是这仍然不能给你想要的东西。 而不是返回文件名,你会得到找到的匹配数。 如果你阅读grep的文档 ,你会看到它说: 为LIST的每个元素计算BLO ...
-
Perl使用file :: slurp读取文件形成目录返回错误(Perl using file::slurp read files form a directory return error)[2022-03-20]
我认为您需要过滤目录并将$ dir添加到文件名: use strict; use warnings; use File::Slurp; my $dir = shift @ARGV; opendir(DH, $dir) or die "Directory Open Error!"; # here, use grep { !-d "$dir/$_"} my @filelist = grep {!-d "$dir/$_"} readdir(DH); my $filename; foreach $filena ... -
/proc/
/fd具有文件描述符。 $ ls -l /proc/$$/fd total 0 lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 0 -> /dev/pts/3 lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 1 -> /dev/pts/3 lrwx------ 1 ikegami pg1404028 64 Jan 12 20:26 2 -> /dev/pts/3 lrwx------ 1 ike ...