![](/img/trans.png)
[英]VBA - For exporting data from Excel to text (cell by cell with separators)
[英]VBA Write Data From Excel Cell to Text/Batch File
我有一個Excel文件,它在單元格A1中存儲文件路徑,並與函數TODAY()串聯以更新該文件路徑。
我還有一個批處理文件,它將文件從一個文件夾移動到另一個文件夾。 我目前使用此更新的excel單元格來獲取新的move batch命令。
如何使用VBA自動將數據從單元格A1中的Sheet1復制到批處理文件?
批處理文件存儲在C:\\ Desktop \\ Batch \\ update.bat
這是下面注釋中的示例代碼,但我只希望它復制工作表1和單元格A1中的數據
Dim FilePath As String
Dim CellData As String
Dim LastCol As Long
Dim LastRow As Long
LastCol = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
FilePath = "C:\Batch\copy.bat"
Open FilePath For Output As #2
For i = 1 To LastRow
For j = 1 To LastCol
If j = LastCol Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + ","
End If
Next j
Write #2, CellData
CellData = ""
Next i
Close #2
MsgBox ("Done")
Dim FilePath As String
Dim CellData As String
FilePath = "C:\Batch\copy.bat"
Open FilePath For Output As #2
r = Worksheet("Sheet1").Range("A1").Text
Print #2 r
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.