Excel宏文件另存为Windows和Mac

时间:2019-03-19 17:26:57

标签: excel vba excel-vba-mac

我有一个Excel文件,其中包含一个宏,该宏可以重新排列值并将其以制表符分隔的格式保存。对于Windows,它可以正常工作,但在Mac上也需要它。我了解的那部分不起作用,是当宏调用函数要求用户“另存为”文件时,提示输入位置和文件名。我认为同一功能在Mac中是不同的。

我不需要任何花哨或复杂的东西。如果用硬编码对代码中的文件名和文件夹进行简化(应该这样做),那么它对我有用。

模块1:

Sub saveTTT()

    template_file = ActiveWorkbook.FullName
    fileSaveName = Application.GetSaveAsFilename( _
    InitialFileName:="C:\Journal_" + VBA.Strings.Format(Now, "ddmmyyyy") + ".IIF"
    fileFilter:="TTT Files (*.ttt), *.ttt")   

    If fileSaveName = False Then
    Exit Sub
    End If

    ActiveWorkbook.SaveAs Filename:= _
    fileSaveName, FileFormat:=xlText, _
    CreateBackup:=False

    file_name_saved = ActiveWorkbook.FullName
    MsgBox "Your TTT Journal has been successfully created at: " & vbCr & vbCr & 
    file_name_saved

    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:= _
    template_file, FileFormat:= _
    xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , 
    CreateBackup:=False
    ActiveWorkbook.Close SaveChanges:=True
End Sub

模块2:

Sub generateTTT()
    ....
    ....
    template_file = ActiveWorkbook.FullName
    fileSaveName = Application.GetSaveAsFilename( _
    InitialFileName:="C:\Journal_" + VBA.Strings.Format(Now, "ddmmyyyy") + ".ttt", 
    _
    fileFilter:="TTT Files (*.ttt), *.ttt")
    If fileSaveName = False Then
    Exit Sub
    End If
    ActiveWorkbook.SaveAs Filename:= _
    fileSaveName, FileFormat:=xlText, _
    CreateBackup:=False
    file_name_saved = ActiveWorkbook.FullName
    MsgBox "Your TTT Journal has been successfully created at: " & vbCr & vbCr & 
    file_name_saved

    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:= _
    template_file, FileFormat:= _
    xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
    , CreateBackup:=False
    ....
    ....
End Sub

0 个答案:

没有答案