VBA Excel到Mac-文件路径

VBA Excel到Mac-文件路径,excel,vba,macos,Excel,Vba,Macos,我以前工作的那个人在PC上使用Excel中的VBA创建报告来跟踪办公室的财务状况。它从多个工作簿中获取信息。我想在Mac上运行它。我将所有相关文件移到了我的计算机上。我知道我需要更新文件路径,但即使这样做我也会迷失方向 当前文件路径如下所示: Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Daily

我以前工作的那个人在PC上使用Excel中的VBA创建报告来跟踪办公室的财务状况。它从多个工作簿中获取信息。我想在Mac上运行它。我将所有相关文件移到了我的计算机上。我知道我需要更新文件路径,但即使这样做我也会迷失方向

当前文件路径如下所示: Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Daily Compass Report Files\”和“CFSPPSSUM-”&SpecifiedDate和“.xls”)

我已使用Get Info从Mac复制了路径。这是正确的吗? Application.Workbooks.Open(“/Users/robert/Documents/Reporting/Dept MathCS Financials/Accounting Files/Dept.Fund Tracking/Daily Compass Report Files/”和“cfsppspum-”&指定数据和“.xls”)

OS X El Capitan版本10.11.3
Microsoft Excel for Mac 2011 14.5.9版

下面是来自主模块的代码

Sub Test()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim i As Integer
i = 6

Dim SpecifiedDate As String
SpecifiedDate = Cells(4, ActiveCell.Column)
SpecifiedDate = Format(SpecifiedDate, "mm/dd/yyyy")
SpecifiedDate = Replace(SpecifiedDate, "/", "-")

Dim TWB As Workbook
Set TWB = ThisWorkbook

Col = ActiveCell.Column

'CFSPPSUM Data Transfer

Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFSPPSUM - " & SpecifiedDate & ".xls")

While TWB.Worksheets("Import-Data").Cells(i, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(i, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(i, 3).Value, _
Workbooks("CFSPPSUM - " & SpecifiedDate & ".xls").Worksheets("Output Data Sheet").Range("$E$9:$AA$100"), 23, False)

i = i + 1
Wend
Cells(6, ActiveCell.Column).Select

Windows("CFSPPSUM - " & SpecifiedDate & ".xls").Close (False)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
Sub Test_Final_Build()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If ActiveCell.Row = 6 Then

Dim SpecifiedDate As String
SpecifiedDate = Cells(4, ActiveCell.Column)
SpecifiedDate = Format(SpecifiedDate, "mm/dd/yyyy")
SpecifiedDate = Replace(SpecifiedDate, "/", "-")

Dim TWB As Workbook
Set TWB = ThisWorkbook

Col = ActiveCell.Column

Dim NSPLoc As String, NSPL As Integer
NSPLoc = Application.WorksheetFunction.Match("NSP SUM", Range("B1:B200"), 0)
NSPL = NSPLoc
Dim D831020Loc As String, D831020L As Integer
D831020Loc = Application.WorksheetFunction.Match("Dept. 831020", Range("B1:B200"), 0)
D831020L = D831020Loc
Dim SPPISUMLoc As String, SPPISUML As Integer, NSPISUMLoc As String, NSPISUML As Integer
SPPISUMLoc = Application.WorksheetFunction.Match("SPP I-SUM", Range("C1:C200"), 0)
SPPISUML = SPPISUMLoc
NSPISUMLoc = Application.WorksheetFunction.Match("NSP I-SUM", Range("C1:C200"), 0)
NSPISUML = NSPISUMLoc

Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer, n As Integer, o As Integer, p As Integer, q As Integer, r As Integer, s As Integer, t As Integer, u As Integer
i = 6   'SPP Sum Location
j = 6   'NSP Sum Location
k = 6
l = 6
m = 6
n = 6
o = 6
p = 6
q = 6
r = 6
s = 6
t = 6
u = 6


    'CFNSPSUM Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPSUM - " & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(j, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(j, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(j, 3).Value, _
    Workbooks("CFNSPSUM - " & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$150"), 57, False)
    j = j + 1
Wend
    Windows("CFNSPSUM - " & SpecifiedDate & ".xls").Activate     'Sum Total Check Figure Import
        Sheets("Sheet1").Select
            Range("BI106").Copy
    TWB.Sheets("Import-Data").Activate
        Cells(NSPISUML, ActiveCell.Column).PasteSpecial xlPasteValues
Windows("CFNSPSUM - " & SpecifiedDate & ".xls").Close (False)


    'CFSPPSUM Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFSPPSUM - " & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(i, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(i, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(i, 3).Value, _
    Workbooks("CFSPPSUM - " & SpecifiedDate & ".xls").Worksheets("Output Data Sheet").Range("$E$9:$AA$100"), 23, False)
    i = i + 1
Wend
Windows("CFSPPSUM - " & SpecifiedDate & ".xls").Activate        'Sum Total Check figure import
    Sheets("Output Data Sheet").Select
        Range("AA80").Copy
    TWB.Sheets("Import-Data").Activate
        Cells(SPPISUML, ActiveCell.Column).PasteSpecial xlPasteValues
Windows("CFSPPSUM - " & SpecifiedDate & ".xls").Close (False)


    'Dept. 831020 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "Dept. 831020 - " & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(k, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(k, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(k, 3).Value, _
    Workbooks("Dept. 831020 - " & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$10:$AY$100"), 47, False)
    k = k + 1
Wend
Windows("Dept. 831020 - " & SpecifiedDate & ".xls").Close (False)


    'Dept. 831021 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "Dept. 831021 - " & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(l, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(l, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(l, 3).Value, _
    Workbooks("Dept. 831021 - " & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$10:$AY$100"), 47, False)
    l = l + 1
Wend
Windows("Dept. 831021 - " & SpecifiedDate & ".xls").Close (False)


    'Dept. 831022 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "Dept. 831022 - " & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(m, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(m, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(m, 3).Value, _
    Workbooks("Dept. 831022 - " & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$10:$AY$100"), 47, False)
    m = m + 1
Wend
Windows("Dept. 831022 - " & SpecifiedDate & ".xls").Close (False)


    'Dept. 831023 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "Dept. 831023 - " & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(n, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(n, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(n, 3).Value, _
    Workbooks("Dept. 831023 - " & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$10:$AY$100"), 47, False)
    n = n + 1
Wend
Windows("Dept. 831023 - " & SpecifiedDate & ".xls").Close (False)


    'CFNSPS01 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS01 - PROVOST BAYH-DOLE RESTRICTED S" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(o, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(o, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(o, 3).Value, _
    Workbooks("CFNSPS01 - PROVOST BAYH-DOLE RESTRICTED S" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    o = o + 1
Wend
Windows("CFNSPS01 - PROVOST BAYH-DOLE RESTRICTED S" & SpecifiedDate & ".xls").Close (False)


    'CFNSPS02 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS     Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS02 - N16 SCIENCE HIRE INITIATIVE" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(p, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(p, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(p, 3).Value, _
    Workbooks("CFNSPS02 - N16 SCIENCE HIRE INITIATIVE" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    p = p + 1
Wend
Windows("CFNSPS02 - N16 SCIENCE HIRE INITIATIVE" & SpecifiedDate & ".xls").Close (False)


    'CFNSPS03 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS03 - MICHELANGELO GRIGNI START-UP F" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(q, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(q, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(q, 3).Value, _
    Workbooks("CFNSPS03 - MICHELANGELO GRIGNI START-UP F" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    q = q + 1
Wend
Windows("CFNSPS03 - MICHELANGELO GRIGNI START-UP F" & SpecifiedDate & ".xls").Close (False)


    'CFNSPS04 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS04 - CLS J Taylor" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(r, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(r, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(r, 3).Value, _
    Workbooks("CFNSPS04 - CLS J Taylor" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    r = r + 1
Wend
Windows("CFNSPS04 - CLS J Taylor" & SpecifiedDate & ".xls").Close (False)


    'CFNSPS05 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS05 - Equipment - Taylor" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(s, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(s, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(s, 3).Value, _
    Workbooks("CFNSPS05 - Equipment - Taylor" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    s = s + 1
Wend
Windows("CFNSPS05 - Equipment - Taylor" & SpecifiedDate & ".xls").Close (False)


    'CFNSPS06 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS06 - SOM Equipment" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(t, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(t, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(t, 3).Value, _
    Workbooks("CFNSPS06 - SOM Equipment" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    t = t + 1
Wend
Windows("CFNSPS06 - SOM Equipment" & SpecifiedDate & ".xls").Close (False)


    'CFNSPS07 Data Transfer
Application.Workbooks.Open ("C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept. Fund Tracking\Daily Compass Report Files\" & "CFNSPS07 - JACKSON MATH AND SCIENCE FUND" & SpecifiedDate & ".xls")
While TWB.Worksheets("Import-Data").Cells(u, 3).Value <> "END"
On Error Resume Next
    TWB.Worksheets("Import-Data").Cells(u, Col) = Application.WorksheetFunction.VLookup(TWB.Worksheets("Import-Data").Cells(u, 3).Value, _
    Workbooks("CFNSPS07 - JACKSON MATH AND SCIENCE FUND" & SpecifiedDate & ".xls").Worksheets("Sheet1").Range("$E$11:$BI$200"), 57, False)
    u = u + 1
Wend
Windows("CFNSPS07 - JACKSON MATH AND SCIENCE FUND" & SpecifiedDate & ".xls").Close (False)

TWB.Sheets("Import-Data").Activate
Cells(6, CLoc).Select

TWB.Sheets("Dept. NSPs & SPPs").Activate
Application.Calculation = xlCalculationAutomatic
Columns(ActiveCell.Column).AutoFit

Else
    MsgBox ("Please select the correct cell for Import")
End If

Application.ScreenUpdating = True

End Sub
子测试()
Application.ScreenUpdating=False
Application.Calculation=xlCalculationManual
作为整数的Dim i
i=6
Dim指定数据为字符串
SpecifiedDate=单元格(4,ActiveCell.Column)
SpecifiedDate=格式(SpecifiedDate,“mm/dd/yyyy”)
SpecifiedDate=替换(SpecifiedDate,“/”,“-”)
将TWB设置为工作簿
设置TWB=ThisWorkbook
Col=ActiveCell.Column
“CFSPPSUM数据传输
Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Daily Compass Report Files\”和“CFSPPSSUM-”&SpecifiedDate和“.xls”)
而TWB.工作表(“导入数据”).单元格(i,3).值“结束”
出错时继续下一步
TWB.工作表(“导入数据”).Cells(i,Col)=Application.WorksheetFunction.VLookup(TWB.工作表(“导入数据”).Cells(i,3).值_
工作手册(“CFSPPSUM-”&SpecifiedDate&“.xls”)。工作表(“输出数据表”)。范围($E$9:$AA$100),23,假)
i=i+1
温德
单元格(6,ActiveCell.Column)。选择
Windows(“CFSPPSUM-”和SpecifiedDate&“.xls”)。关闭(False)
Application.Calculation=xlCalculationAutomatic
Application.ScreenUpdating=True
端接头
子测试\最终\构建()
Application.ScreenUpdating=False
Application.Calculation=xlCalculationManual
如果ActiveCell.Row=6,则
Dim指定数据为字符串
SpecifiedDate=单元格(4,ActiveCell.Column)
SpecifiedDate=格式(SpecifiedDate,“mm/dd/yyyy”)
SpecifiedDate=替换(SpecifiedDate,“/”,“-”)
将TWB设置为工作簿
设置TWB=ThisWorkbook
Col=ActiveCell.Column
Dim NSPLoc为字符串,NSPL为整数
NSPLoc=Application.WorksheetFunction.Match(“NSP总和”,范围(“B1:B200”),0)
NSPL=NSPLoc
尺寸D831020Loc为字符串,D831020L为整数
D831020Loc=Application.WorksheetFunction.Match(“部门831020”,范围(“B1:B200”),0)
D831020L=D831020Loc
Dim SPPISUMLoc为字符串,SPPISUML为整数,NSPISUMLoc为字符串,NSPISUML为整数
SPPISUMLoc=Application.WorksheetFunction.Match(“SPP I-SUM”,范围(“C1:C200”),0)
SPPISUML=SPPISUMLoc
NSPISUMLoc=Application.WorksheetFunction.Match(“NSP I-SUM”,范围(“C1:C200”),0)
NSPISUML=NSPISUMLoc
Dim i为整数,j为整数,k为整数,l为整数,m为整数,n为整数,o为整数,p为整数,q为整数,r为整数,s为整数,t为整数,u为整数
i=6'SPP和位置
j=6'NSP和位置
k=6
l=6
m=6
n=6
o=6
p=6
q=6
r=6
s=6
t=6
u=6
'CFNSPSUM数据传输
Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Daily Compass Report Files\”和“CFNSPSUM-”&指定日期和“.xls”)
而TWB.工作表(“导入数据”).单元格(j,3).值“结束”
出错时继续下一步
TWB.工作表(“导入数据”).Cells(j,Col)=Application.WorksheetFunction.VLookup(TWB.工作表(“导入数据”).Cells(j,3).值_
工作手册(“CFNSPSUM-”&指定日期和“.xls”)。工作表(“表1”)。范围($E$11:$BI$150),57,假)
j=j+1
温德
Windows(“CFNSPSUM-”&SpecifiedDate&“.xls”)。激活“总和检查数字导入”
图纸(“图纸1”)。选择
范围(“BI106”)。副本
TWB.表格(“导入数据”)。激活
单元格(NSPISUML,ActiveCell.Column).paste特殊值
Windows(“CFNSPSUM-”和SpecifiedDate&“.xls”).Close(False)
“CFSPPSUM数据传输
Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Daily Compass Report Files\”和“CFSPPSSUM-”&SpecifiedDate和“.xls”)
而TWB.工作表(“导入数据”).单元格(i,3).值“结束”
出错时继续下一步
TWB.工作表(“导入数据”).Cells(i,Col)=Application.WorksheetFunction.VLookup(TWB.工作表(“导入数据”).Cells(i,3).值_
工作手册(“CFSPPSUM-”&SpecifiedDate&“.xls”)。工作表(“输出数据表”)。范围($E$9:$AA$100),23,假)
i=i+1
温德
Windows(“CFSPPSUM-”和SpecifiedDate&“.xls”)。激活“总和检查数字导入”
工作表(“输出数据表”)。选择
范围(“AA80”)。副本
TWB.表格(“导入数据”)。激活
单元格(SPPISUML、ActiveCell.Column).粘贴特殊XLPasteValue
Windows(“CFSPPSUM-”和SpecifiedDate&“.xls”)。关闭(False)
“部门831020数据传输
Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Daily Compass Report Files\”和“Dept.831020-”&SpecifiedDate和“.xls”)
而TWB.工作表(“导入数据”).单元格(k,3).值“结束”
出错时继续下一步
TWB.工作表(“导入数据”).Cells(k,Col)=Application.WorksheetFunction.VLookup(TWB.工作表(“导入数据”).Cells(k,3).值_
工作手册(“部门831020-”&指定日期和“.xls”)。工作表(“表1”)。范围($E$10:$AY$100),47,假)
k=k+1
温德
Windows(“部门831020-”&指定数据和“.xls”)。关闭(False)
“部门831021数据传输
Application.Workbooks.Open(“C:\Users\Chris Treeman\My Documents\Dept MathCS Financials\Accounting Files\Dept.Fund Tracking\Dail