AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1439429
Accepted
Paul Gibson
Paul Gibson
Asked: 2019-05-22 07:46:09 +0800 CST2019-05-22 07:46:09 +0800 CST 2019-05-22 07:46:09 +0800 CST

导出文本文件但继续编辑 xlsx 文件

  • 772

我使用 excel 生成文本文件,然后将这些文件解析为数据库的输入。当我必须将 xlsx 文件另存为文本文件并关闭 excel 时,我总是很恼火,因为现在我正在 excel 中编辑文本文件。有没有一种方法我只是看不到生成文本文件但在 excel 中保持 xlsx 文件打开?

microsoft-excel
  • 1 1 个回答
  • 36 Views

1 个回答

  • Voted
  1. Best Answer
    harrymc
    2019-05-22T11:35:32+08:002019-05-22T11:35:32+08:00

    为此,您需要一个 VBA 宏,它可能如下所示:

    Sub WriteTextFile()
      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
      CellData = ""
    
      FilePath = Application.DefaultFilePath & "\euth.csv"
    
      Open FilePath For Output As #2
    
      For i = 1 To LastRow
        For j = 1 To LastCol
    
          If j = LastCol Then
            CellData = CellData + TrimtActiveCell(i, j).Value)
          Else
            CellData = CellData + TrimtActiveCell(i, j).Value) + ","
          End If
    
          Next j
    
          Write #2, CellData
          CellData = ""
        Next i
    
        Close #2
    
        MsgBox ("Done")
    End Sub
    

    您可以根据需要修改子例程,可以添加“euth.csv”作为参数或提示输入它。如果电子表格只有一列,则可以大大简化此代码。

    有关上面使用的命令的解释,请参阅文章 Writing to text files in Excel VBA /

    • 0

相关问题

  • 带有“和”运算符的 Excel 数据透视表

  • 如何对整列使用 Excel 的 LENGTH 函数?

  • Excel 数组(2 个变量)

  • 如何从 WSL 打开 office 文件

  • VBA根据文件名重命名工作表

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve