为什么会出现vbscript编译错误

时间:2019-04-05 13:29:39

标签: excel vba vbscript

stackoverflow的新手,希望能得到一些帮助。我收到此错误:

  

标题:程序包验证错误

     

包装验证错误

     
     

其他信息:

     

CSV_File_Reformat错误[ActiveX脚本任务]:用户脚本抛出了一个错误。      例外:“错误代码:0
     错误源= Microsoft VBScript编译错误
     错误说明:语句的预期结尾
     第12行出现错误
     “。

     

CSV_File_Reformat错误:任务验证期间存在错误。

     

(Microsoft.DataTransformationServices.VsIntegration)


按钮:

确定

此代码在VBA中运行时有效,但是当我在SSIS包中将其作为VBScript尝试时,会引发此错误。

代码如下:

Function Weekly_Upload_Reformat_IPS_File()

Dim xl_app
Dim wb
Dim lastRow


Set xl_app = CreateObject("Excel.Application")
Set wb = Workbooks.Open("\\fs1-pdc-plpgh\Transportation - DW\IPS\TFS_FULL_DATA_WEEKLY_*")

For Each wb In Application.Workbooks
   If wb.Name Like "TFS_FULL_DATA_WEEKLY_*" Then wb.Activate
Next wb

Application.DisplayAlerts = False

Rows("1:1").Select

Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

Range("A1").FormulaR1C1 = "Detail"
Range("B1").FormulaR1C1 = "Pro Number"
Range("C1").FormulaR1C1 = "Primary Bill of Lading"
Range("D1").FormulaR1C1 = "PO Number"
Range("E1").FormulaR1C1 = "Invoice Number"
Range("F1").FormulaR1C1 = "Date-Received at IPS"
Range("G1").FormulaR1C1 = "Date-Shipment"
Range("H1").FormulaR1C1 = "Date-Invoice"
Range("I1").FormulaR1C1 = "Date-Delivery Date"
Range("J1").FormulaR1C1 = "Delivery Time"
Range("K1").FormulaR1C1 = "Carrier-SCAC Code"
Range("L1").FormulaR1C1 = "Carrier-Name"
Range("M1").FormulaR1C1 = "Carrier-Major Mode"
Range("N1").FormulaR1C1 = "Carrier-Account Number"
Range("O1").FormulaR1C1 = "Received From"
Range("P1").FormulaR1C1 = "EDI/Paper (E/P)"
Range("Q1").FormulaR1C1 = "Invoice Type (Org/BD/Supp)"
Range("R1").FormulaR1C1 = "Accessorial-Description"
Range("S1").FormulaR1C1 = "Accessorial-Net"
Range("T1").FormulaR1C1 = "Shipper Name"
Range("U1").FormulaR1C1 = "Shipper Address"
Range("V1").FormulaR1C1 = "Shipper City"
Range("W1").FormulaR1C1 = "Shipper State"
Range("X1").FormulaR1C1 = "Shipper Country"
Range("Y1").FormulaR1C1 = "Shipper Zip"
Range("Z1").FormulaR1C1 = "Consignee Contact"
Range("AA1").FormulaR1C1 = "Consignee Name"
Range("AB1").FormulaR1C1 = "Consignee Address"
Range("AC1").FormulaR1C1 = "Consignee City"
Range("AD1").FormulaR1C1 = "Consignee State"
Range("AE1").FormulaR1C1 = "Consignee Country"
Range("AF1").FormulaR1C1 = "Consignee Zip"
Range("AG1").FormulaR1C1 = "Invoice Status (Pay/Rej/Hold)"
Range("AH1").FormulaR1C1 = "Currency"
Range("AI1").FormulaR1C1 = "Status/Week Ending Date"
Range("AJ1").FormulaR1C1 = "Check Number"
Range("AK1").FormulaR1C1 = "Process Loc (DataEntry/Audit)"
Range("AL1").FormulaR1C1 = "Payment Type (Payment/Credit/Debit)"
Range("AM1").FormulaR1C1 = "Terms"
Range("AN1").FormulaR1C1 = "Dim Factor"
Range("AO1").FormulaR1C1 = "Weight-Actual"
Range("AP1").FormulaR1C1 = "Weight-As Wgt"
Range("AQ1").FormulaR1C1 = "WGT Measure:pounds/kilos"
Range("AR1").FormulaR1C1 = "Pieces"
Range("AS1").FormulaR1C1 = "Number of Containers"
Range("AT1").FormulaR1C1 = "International Code"
Range("AU1").FormulaR1C1 = "Delivery Term (Door-Door/Airp-Airp/Etc)"
Range("AV1").FormulaR1C1 = "Service Level (Next Day/2nd Day/Etc)"
Range("AW1").FormulaR1C1 = "Client Mode"
Range("AX1").FormulaR1C1 = "Index Number"
Range("AY1").FormulaR1C1 = "Freight Class"

Range("B:E, AJ:AJ, AX:AX").Select
Selection.NumberFormat = "0"

Cells.Replace What:=",", Replacement:="", LookAt:=xlPart, SearchOrder:= _
    xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="'", Replacement:="", LookAt:=xlPart, SearchOrder:= _
    xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="""", Replacement:="", LookAt:=xlPart, SearchOrder:= _
    xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Columns("W:W").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("W1").FormulaR1C1 = "Shipper City"
Range("W2").FormulaR1C1 = "=TRIM(RC[-1])"
lastRow = Range("V" & Rows.Count).End(xlUp).Row
Range("W2").AutoFill Destination:=Range("W2:W" & lastRow)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Columns("V:V").Delete

Columns("AD:AD").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("AD1").FormulaR1C1 = "Consignee City"
Range("AD2").FormulaR1C1 = "=TRIM(RC[-1])"
lastRow = Range("AC" & Rows.Count).End(xlUp).Row
Range("AD2").AutoFill Destination:=Range("AD2:AD" & lastRow)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Columns("AC:AC").Delete

Columns("AZ:AZ").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("AZ1").FormulaR1C1 = "Freight Class"
Range("AZ2").FormulaR1C1 = "=TRIM(RC[-1])"
lastRow = Range("AY" & Rows.Count).End(xlUp).Row
Range("AZ2").AutoFill Destination:=Range("AZ2:AZ" & lastRow)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Columns("AY:AY").Delete

ActiveSheet.Range("A:AY").AutoFilter Field:=9, Criteria1:= _
    "0001-01-01"
Range("I2:I" & lastRow).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.ClearContents
ActiveSheet.Range("A:AY").AutoFilter Field:=9

ActiveWorkbook.SaveAs Filename:="\\fs1-pdc-plpgh\Transportation - DW\IPS\Staging\IPS Upload.csv", _
    FileFormat:=xlCSV, CreateBackup:=False

End Function

1 个答案:

答案 0 :(得分:0)

VBScriptVBA不可互换。 VBScriptVBA的子集,因此不能简单地将excel宏复制粘贴到.vbs文件并运行。

否则,您的错误"Error Description: Expected end of statement"表示您在字符串上缺少引号,或者您缺少方程式的一部分(例如,如果您写my_var =时在表达式的另一侧没有任何内容) =

我还认为Like中没有VBScript关键字,请改用Left(wb.Name, Len("TFS_FULL_DATA_WEEKLY_")) = "TFS_FULL_DATA_WEEKLY_"

  

我建议您将VBA代码放入excel文件中,然后使用VBScript打开文件并触发宏