将文件夹中的所有文件从.html转换为.xlsx,并使用VBA另存为文件名
我的问题是,正如我的标题所述 将文件夹中的所有文件从HTML(从浏览器下载)转换为.xlsx格式将文件夹中的所有文件从.html转换为.xlsx,并使用VBA另存为文件名,html,macos,excel,excel-2011,vba,Html,Macos,Excel,Excel 2011,Vba,我的问题是,正如我的标题所述 将文件夹中的所有文件从HTML(从浏览器下载)转换为.xlsx格式 我使用相同的文件夹路径存储我想要转换的文件,然后每天替换它 每天使用的文件数量将发生变化 没有“文件掩码”,但该文件夹中只有相关文件,没有子文件夹 必须打开文件,将其转换为xlsx,然后使用与源文件相同的名称再次保存 冲洗并重复,直到所有文件都已转换并保存在同一个文件夹(或不同的文件夹,如果更容易) 我使用的是Excel 2011(用于Mac),因此文件路径会有点不同,但是如果它只是VBA代码,在这
:
分隔,而不是用\
分隔。e、 g.Macintosh HD:用户:文档:R7M:规划:位置
Private Sub CommandButton1_Click()
Dim MyFolder As String
Dim myfile As String
Dim folderName As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
folderName = .SelectedItems(1)
End If
End With
myfile = Dir(folderName & "\*.txt")
Do While myfile <> ""
Workbooks.OpenText Filename:=folderName & "\" & myfile
'save as excel file
ActiveWorkbook.SaveAs Filename:=folderName & "\" & Replace(myfile, ".txt", ".xls")
'use below 3 lines if you want to close the workbook right after saving, so you dont have a lots of workbooks opened
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
myfile = Dir
Loop
End Sub
Private子命令按钮1\u单击()
将MyFolder设置为字符串
将myfile设置为字符串
Dim folderName作为字符串
使用Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect=False
如果.Show=-1,则
folderName=.SelectedItems(1)
如果结束
以
myfile=Dir(folderName&“\*.txt”)
当我的文件“”时执行此操作
Workbooks.OpenText文件名:=folderName&“\”&myfile
'另存为excel文件
ActiveWorkbook.SaveAs文件名:=folderName&“\”&Replace(myfile、.txt、.xls)
'如果要在保存工作簿后立即关闭工作簿,则请使用下面3行,这样您就不会打开很多工作簿
Application.DisplayAlerts=False
活动工作簿。关闭
Application.DisplayAlerts=True
myfile=Dir
环
端接头
任何帮助都会很好 在复制/粘贴过程中,您几乎只需将正确的目标传递到。你的问题是什么?代码陷入了“Application.FileDialog(msoFileDialogFolderPicker)”中。我尝试更改文件格式并使文件夹位置适合我的系统,但没有效果。您可以硬编码
folderName=“HD:Users:Documents:R7M:Planning:Locations”
或选中此选项