sách gpt4 ai đã đi

excel - 将数据从 Excel 复制到记事本

In lại 作者:行者123 更新时间:2023-12-02 14:25:24 29 4
mua khóa gpt4 Nike

Tôi sử dụng SendKeys Excel VBA 函数将数据从 Excel 复制到记事本。

我希望避免使用发送 key 。

我有这个代码:

sub test()

dim wb as Workbook
set wb = "C:\Documents\test.xlsx"
wb.Sheets(2).Range("C2:C" & lRow).Copy
myApp = Shell("Notepad.exe", vbNormalFocus)
SendKeys "^v"
Application.CutCopyMode = False
wb.Sheets(2).Range("C2:C" & lRow).NumberFormat = "@"
end sub

这只是将数据从Excel复制到记事本,但在Excel文件中做了一些更正后,我希望将记事本中的数据从C2开始复制到Excel。

1 Câu trả lời

Đây làSendKeys的替代过程:

  • 从工作表上的一系列单元格中获取值

  • 复制到剪贴板

  • 将剪贴板内容获取到字符串

  • 将该字符串保存到临时文件

  • 使用临时文件的内容打开 Notepad.exe

Mã số:

Option Explicit

Sub OpenNotepadWithTempFileWithClipboardContent()

Dim rngData As Range
Dim strData As String
Dim strTempFile As String

' copy some range values
Set rngData = Sheet3.Range("B1:B5")
rngData.Copy

' get the clipboard data
' magic code for is for early binding to MSForms.DataObject
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.GetFromClipBoard
strData = .GetText
End With

' write to temp file
strTempFile = "D:\temp.txt"
With CreateObject("Scripting.FileSystemObject")
' true to overwrite existing temp file
.CreateTextFile(strTempFile, True).Write strData
End With

' open notepad with tempfile
Shell "cmd /c ""notepad.exe """ & strTempFile & """", vbHide

End Sub

关于excel - 将数据从 Excel 复制到记事本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42224880/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com