选择范围和复制/粘贴到记事本-差不多完成了 [英] select range & copy/paste to notepad - Almost done

查看:58
本文介绍了选择范围和复制/粘贴到记事本-差不多完成了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的工作和测试(确实非常可悲),我终于设法在工作表中选择了一个范围,然后将其复制/粘贴到记事本中.此后,该文件应由另一个应用读取.不幸的是,该应用拒绝了文件,我无法调试原因.我唯一的消息是在最后一行上发生错误.

After a lot of work and testing (very pathetic indeed), I finally managed to select a range in worksheets, then copy/paste it in Notepad. The file shall be thereafter readen by another app. Unfortunately, the app reject the file and there is no way for me to debug why. The only message I have is an error occuring at last line.

令人惊讶的是,当我手动将粘贴复制粘贴到记事本时,它可以工作.据我所知,两个txt文件(一个用我的 sub()编写的文件和一个用CP手工编写的文件)完全相同.我想我的眼睛错了.我怀疑最后一行的末尾或最后一行的下方可能有一些我看不到的 空白 .据我说,我唯一不完全了解的代码部分是当前问题所在的地方.

Surprisingly, when I copy-paste to notepad by hand, it works. As far as my eyes can see, both txt files (the one writen with my sub() and the one from CP by hand) are exactly the same. I guess my eyes are wrong. I suspect there is at the end of last line or below last row maybe some white space I can not see. The only part of code I do not fully understand is, according to me, the place of the current issue.

在我的部分代码下面找到:

Find below part of my code:

[code]
' RngSelect is a Variant and effectively a range of cells 
' Txt is a Variant
' LastRow is a Long equal to last row number of my range

With RngSelect
For Lg1 = 1 To LastRow
    Txt = Txt & vbCrLf & Join$(Application.Transpose(Application.Transpose(.Rows(Lg1).Value)),vbTab)   ' copy each row    
Next
End With

Open FilePath For Output As #1
Print #1, Mid$(Txt, Len(vbCrLf) + 1)
Close #1

RngSelect = Null
Txt = Null

End Sub

如果有帮助,我要由其他应用程序导入的文件可以采用csv格式.目前,我的分隔符是 Tab .

If it can help, my file to be imported by the other app can be in a csv format. Currently, my delimiter is Tab.

感谢您的帮助.

推荐答案

遵循此然后我不得不修改我的LastRow,因为它是电子表格上的行号,而不是文本文件上的最后一行.现在,我将找到一种附加文本文件中文本的方法.

I then had to modify my LastRow, as it is the row number on my spreadsheet but not the last row number on my text file. I shall now find a way to append the text in the text file.

这篇关于选择范围和复制/粘贴到记事本-差不多完成了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆