English 中文(简体)
选定电池的出口数据按txt格式
原标题:Export data from selected cells into txt format

I have data in a cell which has an equation linked to another cell.

在出口后,它无法找到这些数值,因此是在上述文本档案中写成编号。

也是书面的“;”

Sub ExportRangetoFile()
 Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
问题回答

价值或价值只是将目标范围的价值分配到源范围的价值,而不是使用制版/制版。 这样一来,你就把公式推向新工作局,赢得新工作。

Edit: The 2nd half of your question - try using one of the correct file formats (xlText isn t) for saving comma separated files - see https://learn.microsoft.com/en-us/office/vba/api/excel.xlfileformat

Here is a simple VBA Sub that deals with the OP requirement to use the text displayed not the formula in the cell.

值得注意的是,<代码>Cell的财产为.Text而不是。 价值

Sub sbMakeTXT()
 Dim iRows, iColumns, iRow, iColumn As Long
 Dim sText As String
 Dim sFileName As String
 Dim sTXTLine As String
 Dim sTab As String
 Dim iFileNumber As String
 Dim rSelectedRange As Range
 Set rSelectedRange = Application.Selection
 iColumns = rSelectedRange.Columns.Count
 iRows = rSelectedRange.Rows.Count
 sTab = Chr(9)
 sTXTLine = ""
 sFileName = "C:UsersdavidDesktopa.txt"
 iFileNumber = FreeFile
 Open sFileName For Output As iFileNumber
 For iRow = 1 To iRows
  For iColumn = 1 To iColumns
     Use the .Text in the Cell not .Value to deal with formula results
   sText = Cells(iRow, iColumn).Text
     Remove TABs in case they interfere with the file structure
   sText = Replace(sText, sTab, "")
   sTXTLine = sTXTLine & sTab & sText
  Next iColumn
  Print #iFileNumber, sTXTLine
  sTXTLine = ""
 Next iRow
 Close #iFileNumber
End Sub

Use the following data as test data -

ShipperID CompanyName Phone
1 Speedy Express (503) 555-9831
2 United Package (503) 555-3199
3 Federal Shipping (503) 555-9931




相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...