Need to be able to parse data from multiple user selected files

Hoping to get some help. I’m working with an older established Macro that would open the file browser and allow the selection of multiple files and then parse specific data from them into an excel sheet. I have updated it the best I can and will function except it will only transfer data from the last file selected. What I need is to be able to select multiple files and have it write a new Row for each file. Below is the code I’m using

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>' DLL declarations
Type tagOPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
#If VBA7 Then
Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
#Else
Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
#End If
#If VBA7 Then
Declare PtrSafe Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
#Else
Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
#End If
#If VBA7 Then
Declare PtrSafe Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
#Else
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
#End If
Private Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare PtrSafe Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'// Functions
Function GetFromINI(sSection As String, sKey As String, sDefault As String, sIniFile As String)
Dim sBuffer As String, lRet As Long
' Fill String with 255 spaces
sBuffer = String$(255, 0)
' Call DLL
lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
If lRet = 0 Then
' DLL failed, save default
If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
GetFromINI = sDefault
Else
' DLL successful
' return string
GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
End If
End Function
'// Returns True if successful. If section does not
'// exist it creates it.
Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean
Dim lRet As Long
' Call DLL
lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
AddToINI = (lRet)
End Function
Sub Main()
Dim iRow As Integer
Dim INIFilePath1 As String
Dim DE_DS_0 As Variant
Dim DE_DS_1 As Variant
Dim INIFilePath As Variant
Dim INIFileLoop As String
Dim idx As Integer
INIFilePath1 = BrowseForFile
Application.ScreenUpdating = False
If Len(INIFilePath1) > 0 Then
strOutput = "You selected:" & vbCrLf
INIFilePath = Split(INIFilePath1, Chr$(0))
If UBound(INIFilePath) = 0 Then
idx = 0
Else
idx = 1
End If
For intLoop = idx To UBound(INIFilePath)
strOutput = strOutput & strFolder & INIFilePath(intLoop) & vbCrLf
If intLoop = 0 Then
INIFileLoop = INIFilePath(0)
Else
INIFileLoop = INIFilePath(0) & "" & INIFilePath(intLoop)
End If
If Len(INIFileLoop) > 0 Then
'Find next Blank Row
iRow = 2
Do Until IsEmpty(Cells(iRow, 1))
iRow = iRow + 1
Loop
On Error Resume Next
Cells(iRow, 6) = GetFromINI("DATAENTRY_1", "DE_NM", "", INIFileLoop) 'Data Entry Name
DE_DS_0 = Split(GetFromINI("DATAENTRY_1", "DE_DS_0", "", INIFileLoop), ",")
DE_DS_1 = Split(GetFromINI("DATAENTRY_1", "DE_DS_1", "", INIFileLoop), ",")
'DE_DS_1 = Split(GetFromINI("DATAENTRY_1", "DE_DS_1", "", INIFileLoop), ",")
Cells(iRow, 1) = DE_DS_1(2) 'Part Group
Cells(iRow, 2) = DE_DS_1(4) 'Part Name
Cells(iRow, 3) = DE_DS_0(2) 'Process Group
Cells(iRow, 4) = DE_DS_0(4) 'Process Name
Cells(iRow, 7) = INIFileLoop 'Project Path
Cells(iRow, 8) = DE_DS_1(3) 'Part ID #
Cells(iRow, 9) = DE_DS_0(3) ' Process ID #
End If
Next intLoop
End If
Application.ScreenUpdating = True
End Sub
Function BrowseForFile() As String
Dim strFilter As String
Dim lngFlags As Long
lngFlags = ahtOFN_FILEMUSTEXIST Or _
ahtOFN_HIDEREADONLY Or _
ahtOFN_NOCHANGEDIR Or _
ahtOFN_EXPLORER Or _
ahtOFN_ALLOWMULTISELECT
strFilter = ahtAddFilterItem(strFilter, "InfinityQS Files (*.ipj)", "*.IPJ")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
BrowseForFile = ahtCommonFileOpenSave(InitialDir:="T:InfinityQS ProjectProjects_SPC", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="File Browser")
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
End Function
Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases"), a null character, the skeleton
' (like "*.mdb;*.mda") and a final null character.
If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function
Function ahtCommonFileOpenSave( _
Optional ByRef Flags As Variant, _
Optional ByVal InitialDir As Variant, _
Optional ByVal Filter As Variant, _
Optional ByVal FilterIndex As Variant, _
Optional ByVal DefaultExt As Variant, _
Optional ByVal FileName As Variant, _
Optional ByVal DialogTitle As Variant, _
Optional ByVal hwnd As Variant, _
Optional ByVal OpenFile As Variant) As Variant
If IsMissing(InitialDir) Then InitialDir = CurDir
If IsMissing(Filter) Then Filter = ""
If IsMissing(FilterIndex) Then FilterIndex = 1
If IsMissing(OpenFile) Then OpenFile = True
If IsMissing(DialogTitle) Then DialogTitle = ""
#If VBA7 Then
If OpenFile Then
With Application.FileDialog(3) ' const msoFileDialogFilePicker = 3
.AllowMultiSelect = True
' deal with filters
.Filters.Clear
Dim FiltersArray() As String
FiltersArray = Split(Filter, vbNullChar)
For ct = 0 To UBound(FiltersArray) - 2 Step 2
.Filters.Add FiltersArray(i), FiltersArray(i + 1)
Next
.FilterIndex = FilterIndex
.Title = DialogTitle
If .Show <> 0 Then
ahtCommonFileOpenSave = .SelectedItems(1)
Else
ahtCommonFileOpenSave = vbNullString
End If
End With
Else
' not sure how to do a save file in new VBA... 20181127 Jace Gregg
End If
#Else
' This is the entry point you'll use to call the common
' file open/save dialog. The parameters are listed
' below, and all are optional.
'
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem. See examples.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Open File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFilename As String
Dim strFileTitle As String
Dim fResult As Boolean
' Give the dialog a caption title.
If IsMissing(Flags) Then Flags = 0&
If IsMissing(DefaultExt) Then DefaultExt = ""
If IsMissing(FileName) Then FileName = ""
If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp
' Allocate string space for the returned strings.
strFilename = Left(FileName & String(256, 0), 256)
strFileTitle = String(256, 0)
' Set up the data structure before you call the function
With OFN
.lStructSize = Len(OFN)
.hwndOwner = hwnd
.strFilter = Filter
.nFilterIndex = FilterIndex
.strFile = strFilename
.nMaxFile = Len(strFilename)
.strFileTitle = strFileTitle
.nMaxFileTitle = Len(strFileTitle)
.strTitle = DialogTitle
.Flags = Flags
.strDefExt = DefaultExt
.strInitialDir = InitialDir
' Didn't think most people would want to deal with
' these options.
.hInstance = 0
'.strCustomFilter = ""
'.nMaxCustFilter = 0
.lpfnHook = 0
'New for NT 4.0
.strCustomFilter = String(255, 0)
.nMaxCustFilter = 255
End With
' This will pass the desired data structure to the
' Windows API, which will in turn it uses to display
' the Open/Save As Dialog.
If OpenFile Then
fResult = aht_apiGetOpenFileName(OFN)
Else
fResult = aht_apiGetSaveFileName(OFN)
End If
' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags) Then Flags = OFN.Flags
ahtCommonFileOpenSave = TrimNull(OFN.strFile)
Else
ahtCommonFileOpenSave = vbNullString
End If
#End If
End Function
</code>
<code>' DLL declarations Type tagOPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long strFilter As String strCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long strFile As String nMaxFile As Long strFileTitle As String nMaxFileTitle As Long strInitialDir As String strTitle As String Flags As Long nFileOffset As Integer nFileExtension As Integer strDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type #If VBA7 Then Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _ Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean #Else Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _ Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean #End If #If VBA7 Then Declare PtrSafe Function aht_apiGetSaveFileName Lib "comdlg32.dll" _ Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean #Else Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _ Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean #End If #If VBA7 Then Declare PtrSafe Function CommDlgExtendedError Lib "comdlg32.dll" () As Long #Else Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long #End If Private Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare PtrSafe Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long '// Functions Function GetFromINI(sSection As String, sKey As String, sDefault As String, sIniFile As String) Dim sBuffer As String, lRet As Long ' Fill String with 255 spaces sBuffer = String$(255, 0) ' Call DLL lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile) If lRet = 0 Then ' DLL failed, save default If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile GetFromINI = sDefault Else ' DLL successful ' return string GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1) End If End Function '// Returns True if successful. If section does not '// exist it creates it. Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean Dim lRet As Long ' Call DLL lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile) AddToINI = (lRet) End Function Sub Main() Dim iRow As Integer Dim INIFilePath1 As String Dim DE_DS_0 As Variant Dim DE_DS_1 As Variant Dim INIFilePath As Variant Dim INIFileLoop As String Dim idx As Integer INIFilePath1 = BrowseForFile Application.ScreenUpdating = False If Len(INIFilePath1) > 0 Then strOutput = "You selected:" & vbCrLf INIFilePath = Split(INIFilePath1, Chr$(0)) If UBound(INIFilePath) = 0 Then idx = 0 Else idx = 1 End If For intLoop = idx To UBound(INIFilePath) strOutput = strOutput & strFolder & INIFilePath(intLoop) & vbCrLf If intLoop = 0 Then INIFileLoop = INIFilePath(0) Else INIFileLoop = INIFilePath(0) & "" & INIFilePath(intLoop) End If If Len(INIFileLoop) > 0 Then 'Find next Blank Row iRow = 2 Do Until IsEmpty(Cells(iRow, 1)) iRow = iRow + 1 Loop On Error Resume Next Cells(iRow, 6) = GetFromINI("DATAENTRY_1", "DE_NM", "", INIFileLoop) 'Data Entry Name DE_DS_0 = Split(GetFromINI("DATAENTRY_1", "DE_DS_0", "", INIFileLoop), ",") DE_DS_1 = Split(GetFromINI("DATAENTRY_1", "DE_DS_1", "", INIFileLoop), ",") 'DE_DS_1 = Split(GetFromINI("DATAENTRY_1", "DE_DS_1", "", INIFileLoop), ",") Cells(iRow, 1) = DE_DS_1(2) 'Part Group Cells(iRow, 2) = DE_DS_1(4) 'Part Name Cells(iRow, 3) = DE_DS_0(2) 'Process Group Cells(iRow, 4) = DE_DS_0(4) 'Process Name Cells(iRow, 7) = INIFileLoop 'Project Path Cells(iRow, 8) = DE_DS_1(3) 'Part ID # Cells(iRow, 9) = DE_DS_0(3) ' Process ID # End If Next intLoop End If Application.ScreenUpdating = True End Sub Function BrowseForFile() As String Dim strFilter As String Dim lngFlags As Long lngFlags = ahtOFN_FILEMUSTEXIST Or _ ahtOFN_HIDEREADONLY Or _ ahtOFN_NOCHANGEDIR Or _ ahtOFN_EXPLORER Or _ ahtOFN_ALLOWMULTISELECT strFilter = ahtAddFilterItem(strFilter, "InfinityQS Files (*.ipj)", "*.IPJ") strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT") strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*") BrowseForFile = ahtCommonFileOpenSave(InitialDir:="T:InfinityQS ProjectProjects_SPC", _ Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _ DialogTitle:="File Browser") ' Since you passed in a variable for lngFlags, ' the function places the output flags value in the variable. End Function Function ahtAddFilterItem(strFilter As String, _ strDescription As String, Optional varItem As Variant) As String ' Tack a new chunk onto the file filter. ' That is, take the old value, stick onto it the description, ' (like "Databases"), a null character, the skeleton ' (like "*.mdb;*.mda") and a final null character. If IsMissing(varItem) Then varItem = "*.*" ahtAddFilterItem = strFilter & _ strDescription & vbNullChar & _ varItem & vbNullChar End Function Function ahtCommonFileOpenSave( _ Optional ByRef Flags As Variant, _ Optional ByVal InitialDir As Variant, _ Optional ByVal Filter As Variant, _ Optional ByVal FilterIndex As Variant, _ Optional ByVal DefaultExt As Variant, _ Optional ByVal FileName As Variant, _ Optional ByVal DialogTitle As Variant, _ Optional ByVal hwnd As Variant, _ Optional ByVal OpenFile As Variant) As Variant If IsMissing(InitialDir) Then InitialDir = CurDir If IsMissing(Filter) Then Filter = "" If IsMissing(FilterIndex) Then FilterIndex = 1 If IsMissing(OpenFile) Then OpenFile = True If IsMissing(DialogTitle) Then DialogTitle = "" #If VBA7 Then If OpenFile Then With Application.FileDialog(3) ' const msoFileDialogFilePicker = 3 .AllowMultiSelect = True ' deal with filters .Filters.Clear Dim FiltersArray() As String FiltersArray = Split(Filter, vbNullChar) For ct = 0 To UBound(FiltersArray) - 2 Step 2 .Filters.Add FiltersArray(i), FiltersArray(i + 1) Next .FilterIndex = FilterIndex .Title = DialogTitle If .Show <> 0 Then ahtCommonFileOpenSave = .SelectedItems(1) Else ahtCommonFileOpenSave = vbNullString End If End With Else ' not sure how to do a save file in new VBA... 20181127 Jace Gregg End If #Else ' This is the entry point you'll use to call the common ' file open/save dialog. The parameters are listed ' below, and all are optional. ' ' In: ' Flags: one or more of the ahtOFN_* constants, OR'd together. ' InitialDir: the directory in which to first look ' Filter: a set of file filters, set up by calling ' AddFilterItem. See examples. ' FilterIndex: 1-based integer indicating which filter ' set to use, by default (1 if unspecified) ' DefaultExt: Extension to use if the user doesn't enter one. ' Only useful on file saves. ' FileName: Default value for the file name text box. ' DialogTitle: Title for the dialog. ' hWnd: parent window handle ' OpenFile: Boolean(True=Open File/False=Save As) ' Out: ' Return Value: Either Null or the selected filename Dim OFN As tagOPENFILENAME Dim strFilename As String Dim strFileTitle As String Dim fResult As Boolean ' Give the dialog a caption title. If IsMissing(Flags) Then Flags = 0& If IsMissing(DefaultExt) Then DefaultExt = "" If IsMissing(FileName) Then FileName = "" If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp ' Allocate string space for the returned strings. strFilename = Left(FileName & String(256, 0), 256) strFileTitle = String(256, 0) ' Set up the data structure before you call the function With OFN .lStructSize = Len(OFN) .hwndOwner = hwnd .strFilter = Filter .nFilterIndex = FilterIndex .strFile = strFilename .nMaxFile = Len(strFilename) .strFileTitle = strFileTitle .nMaxFileTitle = Len(strFileTitle) .strTitle = DialogTitle .Flags = Flags .strDefExt = DefaultExt .strInitialDir = InitialDir ' Didn't think most people would want to deal with ' these options. .hInstance = 0 '.strCustomFilter = "" '.nMaxCustFilter = 0 .lpfnHook = 0 'New for NT 4.0 .strCustomFilter = String(255, 0) .nMaxCustFilter = 255 End With ' This will pass the desired data structure to the ' Windows API, which will in turn it uses to display ' the Open/Save As Dialog. If OpenFile Then fResult = aht_apiGetOpenFileName(OFN) Else fResult = aht_apiGetSaveFileName(OFN) End If ' The function call filled in the strFileTitle member ' of the structure. You'll have to write special code ' to retrieve that if you're interested. If fResult Then ' You might care to check the Flags member of the ' structure to get information about the chosen file. ' In this example, if you bothered to pass in a ' value for Flags, we'll fill it in with the outgoing ' Flags value. If Not IsMissing(Flags) Then Flags = OFN.Flags ahtCommonFileOpenSave = TrimNull(OFN.strFile) Else ahtCommonFileOpenSave = vbNullString End If #End If End Function </code>
' DLL declarations
Type tagOPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    strFilter As String
    strCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    strFile As String
    nMaxFile As Long
    strFileTitle As String
    nMaxFileTitle As Long
    strInitialDir As String
    strTitle As String
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    strDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

#If VBA7 Then
Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
#Else
Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
#End If

#If VBA7 Then
Declare PtrSafe Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
#Else
Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
#End If

#If VBA7 Then
Declare PtrSafe Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
#Else
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
#End If

Private Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare PtrSafe Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

'// Functions
Function GetFromINI(sSection As String, sKey As String, sDefault As String, sIniFile As String)
    Dim sBuffer As String, lRet As Long
    ' Fill String with 255 spaces
    sBuffer = String$(255, 0)
    ' Call DLL
    lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
    If lRet = 0 Then
        ' DLL failed, save default
        If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
        GetFromINI = sDefault
    Else
        ' DLL successful
        ' return string
        GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
    End If
End Function

'// Returns True if successful. If section does not
'// exist it creates it.
Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean
    Dim lRet As Long
    ' Call DLL
    lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
    AddToINI = (lRet)
End Function


Sub Main()
      Dim iRow As Integer
      Dim INIFilePath1 As String
      Dim DE_DS_0 As Variant
      Dim DE_DS_1 As Variant
      Dim INIFilePath As Variant
      Dim INIFileLoop As String
      Dim idx As Integer
      
      INIFilePath1 = BrowseForFile
      
      Application.ScreenUpdating = False
      
      
      If Len(INIFilePath1) > 0 Then
        strOutput = "You selected:" & vbCrLf
        INIFilePath = Split(INIFilePath1, Chr$(0))
         If UBound(INIFilePath) = 0 Then
         idx = 0
         Else
         idx = 1
         End If
        For intLoop = idx To UBound(INIFilePath)
           strOutput = strOutput & strFolder & INIFilePath(intLoop) & vbCrLf
           If intLoop = 0 Then
           INIFileLoop = INIFilePath(0)
           Else
           INIFileLoop = INIFilePath(0) & "" & INIFilePath(intLoop)
           End If
           If Len(INIFileLoop) > 0 Then
            'Find next Blank Row
            iRow = 2
            Do Until IsEmpty(Cells(iRow, 1))
                  iRow = iRow + 1
            Loop
            On Error Resume Next
            
            Cells(iRow, 6) = GetFromINI("DATAENTRY_1", "DE_NM", "", INIFileLoop) 'Data Entry Name
            DE_DS_0 = Split(GetFromINI("DATAENTRY_1", "DE_DS_0", "", INIFileLoop), ",")
            DE_DS_1 = Split(GetFromINI("DATAENTRY_1", "DE_DS_1", "", INIFileLoop), ",")
            'DE_DS_1 = Split(GetFromINI("DATAENTRY_1", "DE_DS_1", "", INIFileLoop), ",")
            Cells(iRow, 1) = DE_DS_1(2) 'Part Group
            Cells(iRow, 2) = DE_DS_1(4) 'Part Name
            Cells(iRow, 3) = DE_DS_0(2) 'Process Group
            Cells(iRow, 4) = DE_DS_0(4) 'Process Name
            Cells(iRow, 7) = INIFileLoop 'Project Path
            Cells(iRow, 8) = DE_DS_1(3) 'Part ID #
            Cells(iRow, 9) = DE_DS_0(3) ' Process ID #
           End If
           Next intLoop
       End If
       
       Application.ScreenUpdating = True

End Sub
Function BrowseForFile() As String
    Dim strFilter As String
    Dim lngFlags As Long
    lngFlags = ahtOFN_FILEMUSTEXIST Or _
               ahtOFN_HIDEREADONLY Or _
               ahtOFN_NOCHANGEDIR Or _
               ahtOFN_EXPLORER Or _
               ahtOFN_ALLOWMULTISELECT

    strFilter = ahtAddFilterItem(strFilter, "InfinityQS Files (*.ipj)", "*.IPJ")
    strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
    BrowseForFile = ahtCommonFileOpenSave(InitialDir:="T:InfinityQS ProjectProjects_SPC", _
        Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
        DialogTitle:="File Browser")
    ' Since you passed in a variable for lngFlags,
    ' the function places the output flags value in the variable.
End Function

Function ahtAddFilterItem(strFilter As String, _
    strDescription As String, Optional varItem As Variant) As String

    ' Tack a new chunk onto the file filter.
    ' That is, take the old value, stick onto it the description,
    ' (like "Databases"), a null character, the skeleton
    ' (like "*.mdb;*.mda") and a final null character.

    If IsMissing(varItem) Then varItem = "*.*"
    ahtAddFilterItem = strFilter & _
                strDescription & vbNullChar & _
                varItem & vbNullChar
End Function




Function ahtCommonFileOpenSave( _
        Optional ByRef Flags As Variant, _
        Optional ByVal InitialDir As Variant, _
        Optional ByVal Filter As Variant, _
        Optional ByVal FilterIndex As Variant, _
        Optional ByVal DefaultExt As Variant, _
        Optional ByVal FileName As Variant, _
        Optional ByVal DialogTitle As Variant, _
        Optional ByVal hwnd As Variant, _
        Optional ByVal OpenFile As Variant) As Variant

If IsMissing(InitialDir) Then InitialDir = CurDir
If IsMissing(Filter) Then Filter = ""
If IsMissing(FilterIndex) Then FilterIndex = 1
If IsMissing(OpenFile) Then OpenFile = True
If IsMissing(DialogTitle) Then DialogTitle = ""


#If VBA7 Then
    If OpenFile Then
        
        With Application.FileDialog(3) ' const msoFileDialogFilePicker = 3
            .AllowMultiSelect = True
            
            ' deal with filters
            .Filters.Clear
            Dim FiltersArray() As String
            FiltersArray = Split(Filter, vbNullChar)
            For ct = 0 To UBound(FiltersArray) - 2 Step 2
                .Filters.Add FiltersArray(i), FiltersArray(i + 1)
            Next
            
            .FilterIndex = FilterIndex
            .Title = DialogTitle
            
            If .Show <> 0 Then
                ahtCommonFileOpenSave = .SelectedItems(1)
            Else
                ahtCommonFileOpenSave = vbNullString
            End If
        End With
    Else
        ' not sure how to do a save file in new VBA... 20181127 Jace Gregg
    End If
#Else
    ' This is the entry point you'll use to call the common
    ' file open/save dialog. The parameters are listed
    ' below, and all are optional.
    '
    ' In:
    ' Flags: one or more of the ahtOFN_* constants, OR'd together.
    ' InitialDir: the directory in which to first look
    ' Filter: a set of file filters, set up by calling
    ' AddFilterItem. See examples.
    ' FilterIndex: 1-based integer indicating which filter
    ' set to use, by default (1 if unspecified)
    ' DefaultExt: Extension to use if the user doesn't enter one.
    ' Only useful on file saves.
    ' FileName: Default value for the file name text box.
    ' DialogTitle: Title for the dialog.
    ' hWnd: parent window handle
    ' OpenFile: Boolean(True=Open File/False=Save As)
    ' Out:
    ' Return Value: Either Null or the selected filename
    Dim OFN As tagOPENFILENAME
    Dim strFilename As String
    Dim strFileTitle As String
    Dim fResult As Boolean
    
    ' Give the dialog a caption title.
    If IsMissing(Flags) Then Flags = 0&
    If IsMissing(DefaultExt) Then DefaultExt = ""
    If IsMissing(FileName) Then FileName = ""
    If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp
    
    ' Allocate string space for the returned strings.
    strFilename = Left(FileName & String(256, 0), 256)
    strFileTitle = String(256, 0)
    ' Set up the data structure before you call the function
    With OFN
        .lStructSize = Len(OFN)
        .hwndOwner = hwnd
        .strFilter = Filter
        .nFilterIndex = FilterIndex
        .strFile = strFilename
        .nMaxFile = Len(strFilename)
        .strFileTitle = strFileTitle
        .nMaxFileTitle = Len(strFileTitle)
        .strTitle = DialogTitle
        .Flags = Flags
        .strDefExt = DefaultExt
        .strInitialDir = InitialDir
        ' Didn't think most people would want to deal with
        ' these options.
        .hInstance = 0
        '.strCustomFilter = ""
        '.nMaxCustFilter = 0
        .lpfnHook = 0
        'New for NT 4.0
        .strCustomFilter = String(255, 0)
        .nMaxCustFilter = 255
    End With
    ' This will pass the desired data structure to the
    ' Windows API, which will in turn it uses to display
    ' the Open/Save As Dialog.
    If OpenFile Then
        fResult = aht_apiGetOpenFileName(OFN)
    Else
        fResult = aht_apiGetSaveFileName(OFN)
    End If

    ' The function call filled in the strFileTitle member
    ' of the structure. You'll have to write special code
    ' to retrieve that if you're interested.
    If fResult Then
        ' You might care to check the Flags member of the
        ' structure to get information about the chosen file.
        ' In this example, if you bothered to pass in a
        ' value for Flags, we'll fill it in with the outgoing
        ' Flags value.
        If Not IsMissing(Flags) Then Flags = OFN.Flags
        ahtCommonFileOpenSave = TrimNull(OFN.strFile)
    Else
        ahtCommonFileOpenSave = vbNullString
    End If
#End If
End Function


New contributor

Michael Slogar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật