我正在尝试将文件自动保存在指定的文件夹中。比如拥有ResultTest1、ResultTest2、ResultTest3等等。
Dim savedName As String
Dim arNames() As String
Dim myCount As Integer
savedName = Dir$("D:\Users\tmp4jj\Desktop\ComparisonTool\ResultTest*.docx")
Do Until savedName = ""
myCount = myCount + 1
ReDim Preserve arNames(1 To myCount)
arNames(myCount) = savedName
savedName = Dir$
Loop我一直在尝试这段代码,但我不确定它是否真的会起作用。此外,我尝试记录一个宏,在此之前,我更改了保存的文件的目的地的选项。这些密码弹出了,不太确定是否有用。
ActiveDocument.SaveAs2 FileName:="ResultTest.docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=14发布于 2015-04-22 08:36:08
当您想使用具有某些功能的文件时,我建议您使用FileSystemObject com对象。
有许多在项目中使用它的例子,如:
您还可以在循环中使用like操作符查找文件-in (1)示例;如下所示:
IF (f1.name like "ResultTest*.docx") THEN
' Write your code here
END IFOn Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Getting file name by default input window
Flname = InputBox("Enter File Name :", "Creating New File...")
If Flname <> "" Then
' adding a new workbook
Set NewWkbk = Workbooks.Add
' Copy data from a sheet (e.g 5) from current workbook to a sheet (e.g 1) in that new one
ThisWorkbook.Sheets(5).Copy Before:=NewWkbk.Sheets(1)
' Create excel file by saving the new workbook as file name
NewWkbk.SaveAs ThisWorkbook.Path & "\" & Flname
If Err.Number = 1004 Then
NewWkbk.Close
MsgBox "File Name Not Valid."
Exit Sub
End If
End Ifhttps://stackoverflow.com/questions/29790854
复制相似问题