我想在整个电子表格中阅读列和行中的不同值。此外,我想创建一个新的.rtf文档,我在其中填写这些数据。如何在第一列为空之前迭代整个电子表格并将其打印到新文档中? 我希望得到各种反馈。
我目前的代码:
Option Explicit
Public Sub WriteToFile()
On Error GoTo Mistakemark
Dim targetData As String
Dim Line As Integer
ThisWorkbook.Worksheets(1).Activate
targetData = Application.GetSaveAsFilename(FileFilter:="AVL (*.rtf), *.rtf", InitialFileName:="AVL.rtf")
Open targetData For Output As #1
For Line= 1 To 19
Print #1, Cells(Line, 2).Value
Next Line
Close #1
Exit Sub
Mistakemark:
MsgBox Err.Description
End Sub
答案 0 :(得分:0)
Public Sub WriteToFile()
Dim targetData As String
Dim Line As Integer
On Error GoTo Mistakemark
targetData = Application.GetSaveAsFilename(FileFilter:="AVL (*.rtf), *.rtf", InitialFileName:="AVL.rtf")
Open targetData For Output As #1
With ThisWorkbook.Worksheets(1)
For Line = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
MsgBox .Range(.Cells(Line, 2), .Cells(Line, .Columns.Count).End(xlToLeft)).Address
Print #1, Join(Application.Transpose(Application.Transpose(.Range(.Cells(Line, 2), .Cells(Line, .Columns.Count).End(xlToLeft)).Value)), ",")
Next
End With
Close #1
Exit Sub
Mistakemark:
MsgBox Err.Description
Close #1
End Sub