当前位置:回答三>百科知识>Excel VBA怎么实现导入数据自定义格式

Excel VBA怎么实现导入数据自定义格式

2024-06-04 06:47:00 编辑:join 浏览量:544

Excel VBA怎么实现导入数据自定义格式

加上一句代码:

Range("c3:g15000").NumberFormat = "000"

Private Sub CommandButton1_Click()

Range("A3:I15000").Clear

k3dshijihao = "F:\CQ\shishicai.txt"

d3s = "WData3D_All"

cz = k3dshijihao: czmc = d3s

With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;" & cz, Destination:=Range("A3"))

.Name = czmc

.FieldNames = True

.RowNumbers = False

.FillAdjacentFormulas = False

.PreserveFormatting = no

.RefreshOnFileOpen = False

.RefreshStyle = xlInsertDeleteCells

.SavePassword = False

.SaveData = True

.AdjustColumnWidth = True

.RefreshPeriod = 60

.TextFilePromptOnRefresh = False

.TextFilePlatform = xlWindows

.TextFileStartRow = 1

.TextFileParseType = xlDelimited

.TextFileTextQualifier = xlTextQualifierDoubleQuote

.TextFileConsecutiveDelimiter = True

.TextFileTabDelimiter = True

.TextFileSemicolonDelimiter = False

.TextFileCommaDelimiter = True

.TextFileSpaceDelimiter = True

.TextFileColumnDataTypes = Array(1, 0, 1, 1, 1, 1, 1)

.TextFileTrailingMinusNumbers = True

.Refresh BackgroundQuery:=False

End With

Range("A" & (Application.Count(Range("a1:a15000")))).Select

Range("c3:g15000").NumberFormat = "000"

End

End Sub

Private Sub SortRange()

Range("A3:G10002").Select

Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _

OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

标签:自定义,Excel,VBA

版权声明:文章由 回答三 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.huidasan.com/article/111058.html
热门文章