我已经建立了这个宏按钮。我按下按钮后立即收到错误,因为这是为了在PC上运行。
该文件只是要求格式化excel文件的位置。我只需要在Mac上工作,那么有人可以更改代码以允许从Mac环境而不是Windows环境中打开文件吗?
这是Visual Basic编辑器;
Sub Johnny_Calculations()
Dim TotalRow As String
Dim wb As String
Dim ws As String
With Application.FileDialog(msoFileDialogOpen)
.Show
.Title = "Choose File"
.AllowMultiSelect = False
If .SelectedItems.Count = 1 Then
Path = .SelectedItems(1)
End If
End With
Workbooks.OpenText Filename:= _
Path _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:= _
True, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array( _
1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, _
1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array _
(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), _
Array(22, 1), Array(23, 1)), TrailingMinusNumbers:=True
wb = ActiveWindow.Caption
ws = ActiveSheet.Name
TotalRow = WorksheetFunction.Match("Total", Range("A:A"), 0)
Rows(TotalRow & ":" & TotalRow).Select
Selection.ClearContents
File = "Johnny Calculations.xlsm"
Workbooks(File).Worksheets("Sheet2").Activate
Workbooks(File).Worksheets("Sheet1").Range("B2:C22").Copy
Windows(wb). _
Activate
Sheets.Add After:=ActiveSheet
Range("B2").Select
ActiveSheet.Paste
Columns("B:C").Select
Selection.ColumnWidth = 16.86
Range("C3").Select
Application.CutCopyMode = False
'calculations
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C)"
Range("C6").Select
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C[3])"
Range("C7").Select
ActiveCell.FormulaR1C1 = "=R[-1]C/R[-4]C"
Range("C7").Select
Range("C8").Select
ActiveCell.FormulaR1C1 = _
"=SUM('" & wb & "'!C[4])/SUM('" & wb & "'!C)"
Range("C10").Select
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C[5])"
Range("C11").Select
ActiveCell.FormulaR1C1 = _
"=SUM('" & wb & "'!C[5])/SUM('" & wb & "'!C[4])"
Range("C12").Select
ActiveCell.FormulaR1C1 = _
"=SUM('" & wb & "'!C[6])/SUM('" & wb & "'!C[3])"
Range("C13").Select
ActiveCell.FormulaR1C1 = "=R[-3]C/R[-7]C"
Range("C15").Select
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C[7])"
Range("C16").Select
ActiveCell.FormulaR1C1 = "=R[-1]C/R[-6]C"
Range("C17").Select
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C[10])"
Range("C19").Select
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C[8])"
Range("C20").Select
ActiveCell.FormulaR1C1 = "=IFERROR(R[-1]C/R[-5]C,""No Complaints"")"
Range("C21").Select
ActiveCell.FormulaR1C1 = "=SUM('" & wb & "'!C[9])"
Range("C22").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R[-1]C/R[-19]C"
Range("C23").Select
End Sub