I'm trying to render the fNameAndPath in the code below into a cell on the worksheet the text was imported onto.
I "think" one option is to set the fNameAndPath as a static variable so it can be reused. But . . the code below isn't failing, but neither is it putting the fNameAndPath in the desired cell.
Thanks for taking a look.
Ron
I "think" one option is to set the fNameAndPath as a static variable so it can be reused. But . . the code below isn't failing, but neither is it putting the fNameAndPath in the desired cell.
Thanks for taking a look.
Ron
Code:
Sub tm_ImportPastUsersText()
'Import Active Directory file
' Validated mm-dd-yyyy
'
Application.DisplayAlerts = False
Application.DisplayStatusBar = False
Application.ScreenUpdating = False
'
Sheets("Past User Accounts").Activate
'
Dim LastCol As Integer
Dim LastRow As Long
Dim FileName As Variant
Dim fNameAndPath As Variant
Dim wbk1 As Workbook
Dim wks As Worksheet
Dim Thisws As Worksheet
Application.Volatile True
'
Static Import_FileName
Import_FileName = fNameAndPath
'
Set Thisws = ActiveSheet
'
ChDrive "S:"
ChDir "\AD_Listing\Raw_AD_Users\"
'
'----------------------------------------------------------
MsgBox ("Select the most recent AD User text file to import or [Ctrl] + [Fn] + B (B for Break).")
Do
fNameAndPath = Application.GetOpenFilename(fileFilter:="Text Files (*.txt),*.txt", _
Title:="Select AD User text File To Be Opened")
If fNameAndPath = "False" Then
Exit Sub
End If
If InStr(fNameAndPath, "AD_User") = 0 Then
MsgBox "You can only import an Active Directory report file. Please select the most recent file with 'AD...' in the file name."
End If
Loop Until InStr(fNameAndPath, "AD_User") <> 0
'
'-----------------------------------------------------------
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fNameAndPath, Destination:=Range("$A$1"))
.Name = FileName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "^"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery = False
End With
'
With Thiswksht
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
End With
'
Cells(1, LastCol).Offset(0, 1).Value = Import_FileName
BeforeExit:
'Application.ScreenUpdating = True
'Exit Sub
Range("A1").Select
End Sub