【发布时间】:2021-05-15 04:34:56
【问题描述】:
我正在使用 MS-Access 2003 和 2016 (365),并且我有一个保存为 csv 的 excel 2016 文件。 excel 文件来自我无法控制且无法标准化的应用程序。他们将某些列用于特定类型,而不用于其他类型,因此输出包含 A 到 XU 列。
excel 文件有超过 255 列。
我想使用单列和第 2 列(部件号)和其他多列加载到多个表中,并允许将部件号链接在一起。
I.E.表一将有部件号,第 1 列,第 3 列,第 4 列 .... 第 200 列。
那么表二将是零件编号,第 201 列,第 202 列.....第 400 列。
然后表三等等等等
直到所有列都被加载(这可以是可变的,但大约 650 列)(当前是 excel 中的 XU 列)。
'The first part
#If Win64 Then '64?
Private Declare PtrSafe Function MsgBoxTimeout _
Lib "user32" _
Alias "MessageBoxTimeoutA" ( _
ByVal hwnd As LongPtr, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As VbMsgBoxStyle, _
ByVal wlange As Long, _
ByVal dwTimeout As Long) _
As Long
#Else
Private Declare Function MsgBoxTimeout _
Lib "user32" _
Alias "MessageBoxTimeoutA" ( _
ByVal hwnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As VbMsgBoxStyle, _
ByVal wlange As Long, _
ByVal dwTimeout As Long) _
As Long
#End If
Sub Insert_PPL()
'
' Insert_PPL Macro
' This copies the PPL external data into the PPL table
Application.ScreenUpdating = False
Dim MyFile As String
Dim LastRow As Long
'Error handling
On Error GoTo Err_Insert
'MyFile = Application.GetOpenFilename("Excel Files (*.xl*),*.xl*", , "Select TechnoSearch Download File", "Open", False)
'Workbooks.Open (MyFile)
Worksheets("PPL").Activate
Worksheets("PPL").Cells.Select
Selection.Delete
'Moved the myfile open to after the PPL delete
MyFile = Application.GetOpenFilename("Excel Files (*.csv*),*.csv*", , "Select TechnoSearch Download CSV File", "Open", False)
Workbooks.Open (MyFile)
ActiveSheet.Cells.Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Worksheets("PPL").Select
ActiveSheet.Range("A1").Select
Worksheets("PPL").Paste
Application.DisplayAlerts = True
MsgBox ("PPL has been loaded")
Remove_More_Text
Filter_PPL
Exit Sub
Err_Insert:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
Sub Remove_More_Text()
'
' Remove_More_Text Macro
' Used to remove the additional text in the TechnoSearch File
'
Dim sht As Worksheet
Dim LastRow As Long
Dim rng As Range
Dim str As String
Dim x As Integer
Dim LastWord As String
Set sht = ThisWorkbook.Worksheets("PPL")
Columns("E1:E" + CStr(sht.Rows.Count)).Select
LastRow=sht.Rows.Count
For cnt = 2 To LastRow
Set rng = Range("E" + CStr(cnt))
str = rng.Value
'Get the Character Position of more text
If InStr(str, "more text") = 0 Then
x = Len(str) + 3
ElseIf InStr(str, "more text") < 4 Then
x = 3
Else
x = InStr(str, "more text")
End If
LastWord = Left(str, x - 3)
'Replace the original with the shortened string
rng.Value = LastWord
Call MsgBoxTimeout(0,cnt&" of "&LastRow,"",vbInformation,0,1)
Next
End Sub
【问题讨论】:
-
您的问题是什么?我看到发布的标题,但正文没有解释代码问题。
标签: excel vba ms-access ms-access-2003