手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

Excel怎样快速打开文本文件内容

时间:2024-10-13 01:21:23

1、首先打开Microsoft Office Excel 2007,新建文档并保存文件名《Excel怎样快速打开文本文件内容.xlsm》(割洇佼唔演示文件,下面代码复制到能运行宏的工作簿都可以),并在A1输入“文件夹路径”,如下图。

Excel怎样快速打开文本文件内容

2、鼠标移到当前工作表标签栏“Sheet1”表(需要在哪表计算在哪表),右键,弹出快捷菜单,如下图。

Excel怎样快速打开文本文件内容

3、在快捷菜单找到【查看代码】并单击,打开VBE(宏)编辑界面,如下图。

Excel怎样快速打开文本文件内容

4、在右边代码框中复制下面代码到该框中,如下图。Private Sub Worksheet_Change(ByV锾攒揉敫al Target As Range) '2020-7-20 22:11:39 Dim m As String, m1 As String If Target.Row = 1 And Target.Column = 6 Then m = Range("B1").Text m1 = m & "\" & Target.Text & ".txt" Range("f2:f" & Rows.Count).ClearContents On Error Resume Next With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;" & m1, Destination:=Range("$F$2")) .Name = Target.Text & "_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 936 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(2) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With If Err.Number <> 0 Then MsgBox "文件不存在!" End If End IfEnd Sub

Excel怎样快速打开文本文件内容
Excel怎样快速打开文本文件内容

5、以上操作动态过程如下:

Excel怎样快速打开文本文件内容

6、回到“Sheet1”表窗口,在B1输入文本文件的文件路径,在F1输入文本文件名后,在F2显示该文件内容,操作如下图。

Excel怎样快速打开文本文件内容
Excel怎样快速打开文本文件内容
Excel怎样快速打开文本文件内容

7、如果觉得这篇经验帮到了您,请点击下方的 “投票点赞" 或者“收藏”支持我!还有疑问的话可以点击下方的 “我有疑问”,谢谢啦!

© 手抄报圈