VBA
qq_44390640
没有最好,只有更好,追求简洁、实用!用简单的语句解决问题即可!
欢迎一起讨论2G、4G、5G技术,还有SQL、VBA、PYTHON等编程遇到问题或思路,吉他、魔方也可以一起玩。微号:YINKKH;Q号:403998546!
展开
-
VBA提取最短距离
提取最短距离SELECT D.LO1,D.LA1,D.LO2,D.LA2,D.DIS FROM ( SELECT A.LO AS LO1,A.LA AS LA1,B.LO AS LO2,B.LA AS LA2,111.12*atn(sqr(1-(SIN(a.LA*3.1415/180)*SIN(b.LA*3.1415/180)+COS(a.LA*3.1415/180)*COS(b.LA*3.1415/180)*COS((b.LO-a.LO)*3.1415/180))*(SIN(a.LA*3.1415/原创 2022-05-13 16:49:06 · 294 阅读 · 0 评论 -
VBA输出指定字段并保存为CSV
SUB DATA()Dim cnn, SQL$, a, B, C, D, E, f, G, H, i, L, MDim OUT As Workbook Set cnn = CreateObject("adodb.connection") Set rs = CreateObject("adodb.recordset") cnn.Open "Provider = Microsoft.ace.Oledb.12.0;Extended Properties =TEXT;Dat原创 2021-03-10 09:24:29 · 679 阅读 · 1 评论 -
VBA-行->列
Sub 行转列()Dim dic As Object, i As Long, arr, K, TSet dic = CreateObject("Scripting.Dictionary")arr = Worksheets("源数据").[A1].CurrentRegionWorksheets("结果").Cells.ClearReDim BRR(1 To UBound(arr), 1 To 3) '声明从2到N行,1到2列,如要添加输出字段请修改1 TO 5 For i = 2 To UBou原创 2020-10-14 18:52:25 · 703 阅读 · 0 评论 -
VBA通过FTP提取指定数据的文件名
Sub 提取文件名()Dim strPNAME As StringDim nFNO As IntegerShell "cmd.exe /c DEL " & ThisWorkbook.Path & "\*.log"'Shell "cmd.exe /c DEL " & ThisWorkbook.Path & "\input\*.bat"'Shell "cmd.exe /c DEL " & ThisWorkbook.Path & "\input\*.原创 2020-09-18 08:13:58 · 837 阅读 · 0 评论 -
WIN中SCHTASKS用法(定时执行程序)
SCHTASKS /parameter [arguments]描述: 允许管理员创建、删除、查询、更改、运行和中止本地或远程系统上的计划任 务。替代 AT.exe。参数列表: /Create 创建新计划任务。 /Delete 删除计划任务。 /Query 显示所有计划任务。 /Change 更改计划任务属性。 /Run 立即运行计划任务。 /End原创 2020-07-23 09:52:22 · 2437 阅读 · 0 评论 -
利用VBA创建ACCESS数据库并导入CSV数据
方法一:利用VBA创建ACCESS数据库Sub CR_DB() Dim AC As Object Set AC = CreateObject("ACCESS.APPLICATION") Db = ThisWorkbook.Path & "\test.accdb" If Dir(Db) <> "" Then Kill Db End If With AC .NEWCURRE原创 2020-07-02 08:55:29 · 2325 阅读 · 0 评论 -
利用VBA+ADO转置及合并CSV
SUB 转置()Transfrom 统计项 select 行字段 from (数据源) group by 列字段 pivot 行字段Set cnn = CreateObject("ADODB.CONNECTION")Set RS = CreateObject("ADODB.RECORDSET")cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Ex...原创 2020-04-30 08:58:43 · 632 阅读 · 0 评论 -
VBA提取指定区间的数据
Sub OptionalFeatureLicense() Dim Fs As Object, Ft As Object, S As String Set Fs = CreateObject("Scripting.FileSystemObject") Set d = CreateObject("scripting.dictionary") filePath = Th...原创 2020-04-12 19:14:53 · 2381 阅读 · 0 评论 -
VBA读取逐行读取CSV数据(可指定条件)
Sub 提取部分CSV数据()Dim FileName As StringDim txtLine As StringFileName = ThisWorkbook.Path & "\EUtranCellRelation.csv"Open FileName For Input As #1Open ThisWorkbook.Path & "\output.CSV" For ...原创 2020-04-09 13:30:26 · 7835 阅读 · 2 评论 -
VBA复制文件(如CSV)
Sub copyfile() Dim fso As Object, sf$, df$ Dim fileNameObj As Variant Dim i As Integer fileNameObj = Application.GetOpenFilename("CSV 文件 (*.CSV),*.CSV") If fileNameObj <> Fa...原创 2020-04-01 22:15:18 · 941 阅读 · 0 评论 -
VBA批量替换TXT或.LOG文件内容
Sub 替换()Dim tmp As StringDim file As Stringfile = Dir(ThisWorkbook.Path + "\*.sql")Do While file <> "" Open ThisWorkbook.Path + "\" + file For Binary As #1 str= String(LOF(1), vbNull...原创 2020-01-17 18:39:41 · 2431 阅读 · 0 评论 -
VBA+ADO输出到CSV(注意细节)
SUB 将查询结果保存为CSV ()If CheckBox1.Value = True ThenTEX = "A.EUTRANCELLFDD"ElseIf CheckBox2.Value = True ThenTEX = "A.EUTRANCELLTDD"End IfDim cnn, SQL$, A, B, C, D, E, f, G, H, i, L, M Set cnn...原创 2020-01-06 11:56:56 · 1371 阅读 · 0 评论 -
VBA--汇总故障
Sub 故障汇总() Dim Fs As Object, Ft As Object Set Fs = CreateObject("Scripting.FileSystemObject") filePath = ThisWorkbook.Path & "\" fileName = Dir(filePath & "*.log", vbNormal) ...原创 2019-12-31 13:39:45 · 197 阅读 · 0 评论 -
VBA利用正则提取中文
Function 提取中文(str As String) As String Set regEx = CreateObject("vbscript.regexp") With regEx .Global = 1 .Pattern = "[Function RemoveNarrow(str As String) As String" Set r...原创 2019-12-20 15:40:45 · 3720 阅读 · 0 评论 -
VBA批量输出微图表
指定单元格I行5列生成的折线图,折线图值的范围是:H列I行:DC列I行的值Worksheets("SHEET1").Cells(I, 5).SparklineGroups.Add Type:=xlSparkLine, SourceData:="H" & I & ":DC" & I...原创 2019-12-12 08:25:59 · 336 阅读 · 0 评论 -
VBA+ADO对某一含有字符多行和空值的字段求和(解决标准数据类型不匹配问题)
Sub 分厂家统计()Set cnn = CreateObject("adodb.Connection")Set rs = CreateObject("adodb.Recordset")cnn.Open "Provider = Microsoft.ace.Oledb.12.0;Extended Properties =TEXT;Data Source =" & ThisWork...原创 2019-11-01 10:00:34 · 849 阅读 · 0 评论 -
利用VBA批量导入TXT或LOG文件,并完成筛选汇总(适用于UNIX系统出来的数据)
Sub 批量导入TXT或LOG并完成汇总() Dim Fs As Object, Ft As Object Set Fs = CreateObject("Scripting.FileSystemObject") filePath = ThisWorkbook.Path & "\" fileName = Dir(filePath & "*.log", ...原创 2019-10-24 11:21:11 · 1791 阅读 · 0 评论 -
VBA实时提取股票资金流入TOP
以下是根据和讯网实时提取资金流入股票的TOP情况Sub 实时提取股票资金流入TOP() Dim tmp(), TEMP1(), S, STR, STR_1, STR_2 As String, arr() As String, xmlhttp As Object, I, J, N As Long Worksheets("实时资金流入统计").Cells.Clear S...原创 2019-10-16 16:07:36 · 1072 阅读 · 0 评论 -
VBA生成图表方式
Sub 生成图表()Worksheets("图表").ChartObjects.DeleteWith Worksheets("历史记录表")Set MYCHART = .ChartObjects.Add(10, 10, 500, 150) '左,上,长,高With MYCHART.Chart .ChartType = xlLineMarkers .SetSourceData So...原创 2019-10-08 17:20:58 · 2955 阅读 · 0 评论 -
VBA定时刷新(运行程序)
Sub 实时刷新()Call 时间End SubSub 时间()Dim newtimenewtime = Now + TimeValue("00:10:00")模块1.testApplication.OnTime newtime, "时间"End Sub原创 2019-09-30 10:31:36 · 8006 阅读 · 0 评论 -
VBA获取股票历史数据方法
Sub 股票历史记录查询()Worksheets("历史记录表").Cells.Clear ''输出结果表X = Application.CountA(Worksheets("代码").Range("A:A")) ''需要提取的股票代码Y = 1For i = 2 To X dm = IIf(Worksheets("代码").Cells(i, 1) < 600000,...原创 2019-09-29 15:54:06 · 6327 阅读 · 3 评论 -
VBA--正则使用
Sub 正则()Set REG = CreateObject("VBSCRIPT.REGEXP")Dim STR As String, SX = WorksheetFunction.CountA(Worksheets("sheet1").Range("A:A")) For I = 1 To X STR = Cells(I, 1).Text With R...原创 2019-08-05 14:29:53 · 189 阅读 · 0 评论 -
VBA批量合并当前目录下所有EXCELL(含多个SHEETS)
SUB 合并所有SHEET() Dim MyPath, MyNameDim Wb As Workbook, WbN As StringDim I As LongDim Num As LongMyPath = ActiveWorkbook.PathMyName = Dir(MyPath & "\" & "*.xlsx")localName = ActiveWorkbo...原创 2019-07-24 09:05:57 · 732 阅读 · 0 评论 -
VBA+ADO查询ACCESS数据库
Sub 调用ACCESS数据库查询() Dim rst As New ADODB.Recordset Dim myPath As String Dim SQL As String Dim i As Integer myPath = ThisWorkbook.Path & "\新建 Microsoft Access 数据库 (4G-2G).ac...原创 2019-07-24 08:44:33 · 1629 阅读 · 0 评论 -
VBA生成KML文件
Private Sub OptionButton36_Click()Dim i As IntegerDim s As String '存储生成的代码Dim f As String '保存的文件名Dim rng As Rangef = ThisWorkbook.Path & “\GZ.kml” '宏所在的文件内KML文件s = “<kml xmlns=”“http://...原创 2019-07-19 16:17:27 · 969 阅读 · 0 评论 -
ADO+读取、汇总CSV文件
Sub 总输出() ‘’不打开CSV文件进行读取汇总Set CNN = CreateObject("ADODB.CONNECTION")Set RS = CreateObject("ADODB.RECORDSET")CNN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=...原创 2019-07-24 08:48:12 · 1863 阅读 · 0 评论 -
ADO+查询数据库
Sub 查询数据库()Set rs = CreateObject("ADODB.RECORDSET") cnn.Open = "DSN=GSM;uid=ailxl;pwd=ailxl;Database=感知数据库;" 'TABLE=DBO.DATA;" Sql = "SELECT * FROM [Data] DATA WHERE YEAR([Datetime Id(GSM_CE...原创 2019-07-24 08:54:51 · 574 阅读 · 0 评论 -
VBA制作DT(适用ERIC)
Private Sub OptionButton37_Click() 'DT制作Shell "cmd.exe /c DEL " & ThisWorkbook.Path & "\*.mos"Application.Wait Now + TimeValue("00:00:01")Worksheets("脚本模板").ActivateX = WorksheetFunction...原创 2019-07-24 09:15:49 · 358 阅读 · 0 评论 -
VBA批量读取TXT、CSV文件---字段提取异常处理方法(Schema.ini)
Private Sub OptionButton39_Click() '提取功能Set rs = CreateObject("adodb.Recordset")cnn.Open "Provider = Microsoft.ace.Oledb.12.0;Extended Properties =TEXT;Data Source =" & ThisWorkbook.Path & "...原创 2019-07-24 09:20:46 · 1616 阅读 · 0 评论 -
VBA-利用字典代替VLOOKUP
SUB 代替VLOOKUP() Dim d, ar, br, cr, wb As Workbook Set d = CreateObject("Scripting.Dictionary") br = Worksheets("Sheet1").[A1].CurrentRegion '需要配置的数据表 ar = Worksheets("R").[A1].CurrentRe...原创 2019-08-05 15:01:10 · 8866 阅读 · 0 评论 -
VBA--利用字典求和
Sub 字典汇总求和()Dim arr, d As Object, brr()Set d = CreateObject("scripting.dictionary")arr = [a1].CurrentRegionReDim brr(1 To UBound(arr), 1 To 3)For i = 1 To UBound(arr) If Not d.exists(arr(i, 1...原创 2019-08-05 15:16:48 · 3896 阅读 · 0 评论 -
VBA自定义获取股票当天信息
Sub 自定义获取股票信息() Worksheets("输出结果").Cells.Clear Worksheets("输出结果").Range("a1:AE1") = Array("代码", "股票名", "现价", "昨收", "今开", "成交量(手)", "外盘", "内盘", "买一", "买一量(手)", "卖一", "卖一量", "时间", "涨跌", "涨跌幅",...原创 2019-09-27 17:20:11 · 1427 阅读 · 1 评论 -
VBA--分列转置(先分列,再行转列)
Sub 行转列() Dim arr, BRR Worksheets("结果").Cells.Clear arr = Worksheets("TEST").[a1].CurrentRegion N = 2 For i = 2 To UBound(arr) BRR = Split(arr(i, 3), ",") '''''分列,...原创 2019-08-22 12:37:33 · 1577 阅读 · 1 评论 -
VBA+ADO不打开文件对TXT、CSV、EXCEL、ACCESS数据库、远程数据库进行操作(超全、超实用的方法)
BA+ADO不打开文件对TXT、CSV、EXCEL、ACCESS数据库、远程数据库进行数据提取、统计、汇总方法:Set cnn = CreateObject("ADODB.CONNECTION")Set rs = CreateObject("ADODB.RECORDSET"){**1)连接远程数据库方法:***cnn.Open = "DSN=GSM;uid=ailxl;pwd=ailx...原创 2019-08-16 14:21:21 · 3913 阅读 · 0 评论 -
VBA+ADO提取内容并输出到文本(TXT)
SUB 提取指定内定到TXT()Set CNN = CreateObject("ADODB.CONNECTION")Set RS = CreateObject("ADODB.RECORDSET")CNN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\统计.accd...原创 2019-08-16 13:59:28 · 1453 阅读 · 0 评论 -
VBA-单元格格式设置
SUB 格式()Worksheets("申报表" & i).Range("A1:I6").Interior.ColorIndex = 2 Worksheets("申报表" & i).Range("A" & O + 4 & " :J" & O + 4).Borders.LineStyle = xlContinuous Worksheets("申报表" ...原创 2019-08-21 14:03:25 · 775 阅读 · 0 评论 -
VBA中批量新增并命名工作表,删除工作表
SUB 批量增加命名工作表() For L = 1 To 100Sheets.Add(, Sheets("发票表头")).Name = "发票表" & iNEXTEND SUBSUB 批量删除工作表()Application.DisplayAlerts = 0 ‘’‘关闭提示On Error Resume NextX = Worksheets.CountFor i ...原创 2019-08-20 14:06:21 · 3138 阅读 · 0 评论 -
VBA中COPY表1内容到表2
COPY表1包有格式内容到表2中Worksheets("申报表头").Range("A1:J4").Copy Destination:=Worksheets(“结果").Range("a1:j4")原创 2019-08-20 11:07:36 · 3325 阅读 · 2 评论 -
VBA+ADO提取某字段最大值(峰值)
Sub 分类()Dim ADim cnn, SQL$ Set cnn = CreateObject("adodb.connection") Set RS = CreateObject("adodb.recordset") cnn.Open "Provider = Microsoft.ace.Oledb.12.0;Extended Properties =TEXT;Data ...原创 2019-08-14 17:12:47 · 1284 阅读 · 0 评论 -
VBA利用ADO合并多个CSV
Sub 合并多个csv文件为一个文件() Dim cnn As Object, SQL$, MyPath$, MyFile$, m& Set cnn = CreateObject("adodb.connection") Set rs = CreateObject("adodb.recordset") MyPath = ThisWorkbook.Path &a...原创 2019-07-24 13:40:07 · 1801 阅读 · 0 评论