Macbook的VBA-宏未保存输出文件

时间:2019-07-10 15:48:35

标签: excel vba excel-vba-mac

我正在研究MacBook的宏,以分离我们粘贴在文件中的代码。

运行后,代码应显示在我桌面上名为“游览代码”的文件夹中。

但是,文件未保存,宏显示错误。

我尝试了多次调整并更改了文件的位置,但问题仍然存在。

任何建议,我将不胜感激。


Sub create_files()
Application.ScreenUpdating = False
Dim iName, iPath
iName = GetUserNameMac
'Get Path and Workbook Name
'iPath = ActiveWorkbook.Path
iPath = "Macintosh HD:Users:" & iName & ":Desktop:Tour Codes"
Sheets("Data").Select

...
'create files
Dim r1, ddate, gate, id, cap, firstrow, rowcount, newcode
r1 = 2
firstrow = 2
...

    Application.DisplayAlerts = False
    'save file
    ChDir "Macintosh HD:Users:" & iName & ":Desktop:Tour Codes"
    ActiveWorkbook.SaveAs Filename:= _
    iPath & ":" & id & "_" & Format(ddate, "yyyy-mm-dd") & "_" & gate & "_" & firstrow & ".csv", _
        FileFormat:=xlCSV, CreateBackup:=False
    'ActiveWorkbook.SaveAs iPath & ":" & merchWk
    'ActiveWorkbook.SaveAs iPath & "/" & merchWk
    Windows("Gate 1 codes macro.xlsm").Activate

    'copy rows to file
    'Rows(firstrow & ":" & firstrow + rowcount - 2).Select
    Range(Cells(firstrow, 1), Cells(firstrow + rowcount - 2, 1)).Select
    Selection.Copy
    Windows(id & "_" & Format(ddate, "yyyy-mm-dd") & "_" & gate & "_" & firstrow & ".csv").Activate
    'Cells(2, 1).Select
    Cells(1, 1).Select
    ActiveSheet.Paste
    'Columns("A:E").EntireColumn.AutoFit
    Columns("A:A").EntireColumn.AutoFit

    'save file
    Cells(1, 1).Select
    ActiveWorkbook.Save
    ActiveWindow.Close
    Application.DisplayAlerts = True
    Windows("Gate 1 codes macro.xlsm").Activate
    firstrow = r1 - 1
    r1 = firstrow

Loop Until r1 > lastrow
End Sub
Function GetUserNameMac() As String
Dim sMyScript As String
sMyScript = "set userName to short user name of (system info)" & vbNewLine & "return userName"   
GetUserNameMac = MacScript(sMyScript)

End Function

在这些行上出现VBA错误:

error

0 个答案:

没有答案