gpt4 book ai didi

vba - Origin :=65001 in code 放在哪里

转载 作者:行者123 更新时间:2023-12-02 21:34:42 24 4
gpt4 key购买 nike

此问题是上一个问题 here 的后续问题.

根据@Jeeped的回答,解决该问题的最佳方法似乎是将这部分代码插入到宏中:

Origin:=65001

这是为了强制我的代码导入 UTF-8 格式的文件。

现在出现的问题是我无法弄清楚如何或在何处将上面的代码插入到我的宏中。我有以下宏(我在网上找到的 - 但不记得在哪里,所以不能相信),它将大量文件导入到工作簿中,为每个文件创建电子表格。

Sub Extractions()

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.DisplayStatusBar = False

Dim FilesToOpen
Dim x As Integer

On Error GoTo ErrHandler

FilesToOpen = Application.GetOpenFilename _
(fileFilter:="Microsoft Excel Files (*.*?), *.*?", MultiSelect:=True, Title:="Files to Import")

If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If

x = 1
While x <= UBound(FilesToOpen)
Workbooks.Open Filename:=FilesToOpen(x), Delimiter:=Chr(124)
Sheets().Move Before:=ThisWorkbook.Sheets _
(ThisWorkbook.Sheets.Count)
x = x + 1
Wend

ExitHandler:
Application.ScreenUpdating = False
Exit Sub

ErrHandler:
MsgBox Err.Description
Resume ExitHandler
Resume

End Sub

关于如何解决此问题有什么建议吗?

编辑1:

感谢@Rory 的建议。经过更多调查,Origin:=65001 似乎不是 Workbook.Open 中的有效条目。

因此,我想知道在使用上面的代码导入 MFGI 时,是否可以保留文本文件的原始格式(设置为 UTF-8)?

最佳答案

也许这可以给你一个提示。

Sub Test()
Dim FD As FileDialog
Dim FilesToOpen
Dim e
Dim tmp

Set FD = Application.FileDialog(msoFileDialogFilePicker)

With FD
If .Show = -1 Then
appTGGL bTGGL:=False
For Each FilesToOpen In .SelectedItems
tmp = Split(Dir(FilesToOpen), ".")
Select Case tmp(UBound(tmp)) 'the last
Case "xlsx"
MsgBox "2007"
Workbooks.Open Filename:=FilesToOpen
Sheets().Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Case "xlsm"
MsgBox "2007M"
Workbooks.Open Filename:=FilesToOpen
Sheets().Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Case "xls"
MsgBox "2003"
Workbooks.Open Filename:=FilesToOpen
Sheets().Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Case "csv"
MsgBox "CSV"
Workbooks.Open Filename:=FilesToOpen, Delimiter:=Chr(124), Origin:=65001
Sheets().Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Case "txt"
MsgBox "TXT"
Workbooks.Open Filename:=FilesToOpen, Delimiter:=Chr(124), Origin:=65001
Sheets().Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Case Else
MsgBox "NO Ext/Other Ext"
End Select
Next FilesToOpen
appTGGL
Else
MsgBox "No Files were selected"
End If
End With
End Sub

关于vba - Origin :=65001 in code 放在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36036185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com