【发布时间】:2014-05-11 11:38:29
【问题描述】:
我们正在使用 AutoCad 实用程序 CleanupScale 2014,我们希望鼓励用户在使用其他人在生产中提供的 CAD 文件之前先运行该实用程序。此实用程序生成的 CSV 日志文件在导入 Excel 时最容易查看,方法是从文本中获取外部数据然后对其进行格式化。我们希望通过 VBA 脚本尽可能多地自动化此过程。
部分问题是要导入的文件并不总是具有相同的文件或工作表名称。
谁能帮助我们编辑下面的 VBA 脚本,以便在继续格式化和过滤之前提示 CSV 文件从中获取文本?
Sub ScaleListCleanupLog()
' ScaleListCleanupLog Macro
' Format the Scale List Cleanup Log for easier viewing.
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\User\Documents\CleanupScales48.csv", Destination:=Range( _
"$A$1"))
.Name = "CleanupScales48"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Rows("1:1").Select
Selection.Font.Bold = True
Selection.Font.Underline = xlUnderlineStyleSingle
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("B:E").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("E1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$E$24").AutoFilter Field:=5, Criteria1:= _
"=Error saving drawing", Operator:=xlOr
End Sub
【问题讨论】: